Electron: webContents.send() does not send object functions

Created on 25 Dec 2015  路  1Comment  路  Source: electron/electron

Mac OS X 10.11, Electron 0.36.1

If I create an object in the backend process, for instance:

function Person(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;

    this.getFullName = function() {
        return this.firstName + " " + this.lastName;
    }
}

and pass an instance of it to the renderer process:

let sam = new Person("sam", "joe");

mainWindow.webContents.on('did-finish-load', function() {
    mainWindow.webContents.send('person', sam);
})

From the renderer process, I can access the variables of the object (firstName, lastName) but not the function (getFullName()).

Looking at the debug console, the object inside the renderer process appears to be exactly the same as that in the main process, but missing the functions.

>All comments

IPC send serializes the object a-la JSON.stringify

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dangan-ronpa picture dangan-ronpa  路  3Comments

sindresorhus picture sindresorhus  路  3Comments

DanielDignam picture DanielDignam  路  3Comments

feross picture feross  路  3Comments

wsangtoki picture wsangtoki  路  3Comments