2016-11-13 2 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); 
}; 

関数ではありません:this.addClientは、これが発生している理由を私は知らないの行に27this.addClientは、私がNode.jsの上で、このエラーを取得してい

関数ではありません。

+0

あなたのコードが切断され、それをバインドすることができます。すべての投稿をお願いしますか? – Bennett

答えて

1

ほとんどの場合、あなたのthisポインタはあなたが期待するものではありません、あなたは明示的に

this.server = net.createServer(this.onAccept.bind(this); 
    this.server.listen(this.port); 
} 
関連する問題