2016-11-13 170 views
0
this.server = net.createServer(this.onAccept); 
    this.server.listen(this.port); 
} 

Server.prototype.onAccept = function() { 
    var client = new Client(); 

    this.addClient(client); 
}; 

Server.prototype.addClient = function (client) { 
    this.clients.push(client); 
}; 

我得到关于node.js的这个错误:this.addClient不就行了27this.addClient不是函数

功能我不知道为什么会发生。

+0

您的代码被切断。你可以把它全部发布吗? – Bennett

回答

1

最有可能你的this指针是不是你所期望的,可以绑定它明确

this.server = net.createServer(this.onAccept.bind(this); 
    this.server.listen(this.port); 
}