Is it possible to replace this
context when sending an event?
var that = {}, obj = new myType();
// how to pass `that` as the calling context?
obj.emit('myEvent', data);
obj.on('myEvent', function () {
// I need it to arrive with `this`=`that`
});
I'm using the standard EventEmitter
inheritance approach:
In the beginning of my type:
events.EventEmitter.call(this);
Following the type function:
myType.prototype.__proto__ = events.EventEmitter.prototype;
But that seems to override any emit
with whatever context I specified inside myType
function. And when I need a different this
context, I cannot figure out how to send it.