Is there any method that calls the function, but sets the this context to the default value that it has when calling the function by executing fn() ?
This method should take an array and pass the individual elements as arguments to the function, like apply ():
emitter = new EventEmitter(); args = ['foo', 'bar']; // This is the desired result: emitter.emit('event', args[0], args[1], ...); // I can do this using apply, but need to set the context right emitter.emit.apply(emitter, 'event', args); // How can I trim the context from this? emitter.emit.???('event', args);
EDIT. To clarify this, I really care about the value that this will have inside the called function - it should be the "normal" context that it has when emitter.emit() executed, and not a global object or something else, otherwise this sometimes upsets the situation.
source share