Wolfy87/EventEmitter — Issue #22: Wrong object is used to invoke the callback in fire() method
Author: salsita
Created: 2012-01-23 14:32:14+00:00
State: open

I'm using EventEmitter.js with xml-js (https://github.com/Leonidas-from-XIV/node-xml2js) in a Chrome extension with a custom require() implementation to load the (local) script files synchronously. It works great except that xml-js registers the callback without passing in any scope variable explicitly. The line in fire() looks like this:

this.listener.apply(this.scope || this, args);

this.scope is undefined and this is the Event object and not the Parser object from xml-js. I therefore get an error since the callback expects this to be the Parser object. If I change it to the following it works:

this.listener.apply(this.scope || this.instance, args);

Am I misunderstanding how this should work, is xml-js using the EventEmitter in a way you didn't anticipate or is this a bug? If the latter, I'll be happy to post a push request.