mike_hornbeck
mike_hornbeck

Reputation: 1622

Object's properties not accesible when returned by nodeJS server

I was playing with node.js and I came into a problem, that I cannot solve in any way. On the server side I have some objects, that provide public interface for managing them. But the problem is that in this interface I have functions, that are not accesible when returned to frontend. Anyone knows what am I doing wrong or why is that a feature and not a bug ?
Sample test code on server side:

socket.on('F-test', function(){
    var o1 = {
        A: 5
    };

    var o2 = function(){
        this.A = function(){
            return 5;
        }
    };

    var o3 = function(){
        var A = function(){
            return 5;
        }

        return {
            'A': A
        }
    };

    var o4 = function(){
        var that = this;
        that.A = function(){
            return 5;
        }

        return that;
    };

    var o5 = {
        A: function(){
            return 5;
        }
    };

    socket.emit('B-test', {o1: o1, o2: new o2(), o3: new o3(), o4: new o4(), o5: o5});
});

And in the console I get :

enter image description here

Hosting is provided by no.de (Joyent);

Upvotes: 0

Views: 102

Answers (1)

Joe
Joe

Reputation: 82654

The problem is that Functions don't serialize. Only properties will serialize.

Upvotes: 2

Related Questions