Reputation:
How can I pass the net.socket class as argument? My code:
this.server = net.createServer(this.onAccept.bind(this));
this.server.listen(this.port);
}
Server.prototype.onAccept = function () {
// PASS SOCKET AS ARGUMENT HERE
var client = new Client(ONLYMYSOCKETCLASS);
Upvotes: 0
Views: 67
Reputation: 106696
It doesn't really make sense to put onAccept()
on the prototype if you're just going to call .bind()
which returns a (bound) copy of that function. The primary purpose of putting things on a prototype is to get efficient re-use of them among all instances of that object.
onAccept()
will already receive a socket object as its only argument since it's a 'connection'
event handler, so just add that to onAccept()
's function signature and use it:
Server.prototype.onAccept = function (socket) {
// ...
};
Upvotes: 1