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

diracdeltas picture diracdeltas  路  3Comments

tenry92 picture tenry92  路  3Comments

maxogden picture maxogden  路  3Comments

EladBezalel picture EladBezalel  路  3Comments

chonsser picture chonsser  路  3Comments