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
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
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,
'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
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