-
Notifications
You must be signed in to change notification settings - Fork 7.3k
EventEmitter breaking changes in latest builds #4971
Comments
Well sadly these JavaScript libs that are now breaking are doing inheritance wrong. You don't call These now broken libs should switch over to using |
Might be worth making a note on https://github.com/joyent/node/wiki/Api-changes-between-v0.8-and-v0.10 if folks could get bitten by it. Took me all day to figure it out. (Partly as node-inspector also appears to be broken on the latest v0.10 - my Node command-line debugger skills aren't quite as brisk). |
Thanks. Just as a note, but the "Correct Style Inheritance" you demonstrate in the page is actually wrong, as you are not calling the parent constructor from the child constructor. This should be done (as the snippet in the docs at util.inherits actually demonstrates), as if the parent constructor isn't called then any properties it sets won't get created (e.g. such as _events and _maxListeners on EventEmitter). Sample below demonstrates. Not a biggy, but if the doc is going to make a point about "Correct Style Inheritance", it should probably be correct :-)
|
Fixed. On Mon, Mar 11, 2013 at 6:55 PM, billti notifications@github.com wrote:
|
With the change in 4f7f8bb to initialize the _events object in the EventEmitter constructor, the behavior has changed notably. This breaks some popular libraries I use (such as 'jake' for building). The issue is that now the _events object is on the EventEmitter instance, not whatever 'this' called addEventListener. Code that uses a common EventEmitter instance as a constructor function prototype get incorrect behavior now, as all constructed object instances share the same list of handlers.
The below simple test works on 0.8.22, and if I build a commit earlier than the above, but fails from that commit on (both added listeners fire for both Task instances, so eventCount is 4). Simply reverting line 35 in ./lib/events.js to initialize _events to null (or even comment out that line entirely) fixes the issue.
The text was updated successfully, but these errors were encountered: