[nodejs] Re: Passing the socket into the callback

2013-08-22 Thread Floby
EventEmitter handlers are always called in the scope of the EventEmitter instance. On Wednesday, 21 August 2013 07:30:58 UTC+2, Mike Chen wrote: Hi, I am doing a bit of code organization, and I would like to turn the following: client.on('message', function(data) { // do something

Re: [nodejs] Re: Passing the socket into the callback

2013-08-21 Thread Brian Di Palma
You could also just use Function.bind. On Aug 21, 2013 6:40 AM, Mike Chen mikalora...@gmail.com wrote: Nevermind, solved it, had the this wrapped in another function. Thanks, -mike On Wednesday, August 21, 2013 1:30:58 AM UTC-4, Mike Chen wrote: Hi, I am doing a bit of code

Re: [nodejs] Re: Passing the socket into the callback

2013-08-21 Thread Max Gfeller
You could do this: client.on('message', doSomething.bind(client)); function doSomething(args) { // do something this.emit(); } 2013/8/21 Brian Di Palma off...@gmail.com You could also just use Function.bind. On Aug 21, 2013 6:40 AM, Mike Chen mikalora...@gmail.com wrote: Nevermind,

[nodejs] Re: Passing the socket into the callback

2013-08-21 Thread Kamil Leszczuk
'this' will be bound to the EventEmitter instance. This behaviour is implemented around here: https://github.com/joyent/node/blob/master/lib/events.js#L100. So, the following code works as expected (prints called!). var SomeClass = function () { }; util.inherits(SomeClass, EventEmitter); var

[nodejs] Re: Passing the socket into the callback

2013-08-20 Thread Mike Chen
Nevermind, solved it, had the this wrapped in another function. Thanks, -mike On Wednesday, August 21, 2013 1:30:58 AM UTC-4, Mike Chen wrote: Hi, I am doing a bit of code organization, and I would like to turn the following: client.on('message', function(data) { // do something