user6513042
user6513042

Reputation:

Pass net.socket as argument

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

Answers (1)

mscdex
mscdex

Reputation: 106696

  1. 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.

  2. 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

Related Questions