我读到nowjs支持传递对象以及字符串,但由于某种原因,我遇到了问题。这是从他们的只是一个字符串网页上的nowjs例子越来越解析各地和工作为我好,在Nowjs中使用回调参数传递对象
客户端
now.test('foo', function(msg){
console.log(msg);
});
服务器端
everyone.now.test = function(val, callback){
callback(val + ' bar!');
}
下面的代码我试图通过并以val为对象,
客户端
now.test('default', function(msg){
console.log(Object.keys(msg));
console.log(msg.GetEthernet());
});
服务器端
everyone.now.test = function(val, callback){
var profile = honeydConfig.GetProfile(val);
console.log("Got eth " + profile.GetEthernet() + " for profile " + profileName);
callback(profile);
}
在服务器端,它打印GetEthernet功能的正确的输出。在客户端它只是说:“Uncaught TypeError:Object#没有方法'GetEthernet'”并返回Object.keys的空数组。“
就是这样。在服务器端添加“profile.ethernet = profile.GetEtherent()”,它工作。显然它可以发送对象的成员变量而不是方法,这是有道理的。谢谢! – PherricOxide 2012-04-26 17:35:10