开发者

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 :

Object's properties not accesible when returned by nodeJS server

Hosting is provided by no.de (Joyent);


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜