我讀到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