primus / eventemitter3

EventEmitter3 - Because there's also a number 2. And we're faster.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2.0.0 - _events is undefined when extending ee3

stbaer opened this issue · comments

Hi, not sure if this is a bug or if I do something wrong. Before upgrading to 2.0.0 everything worked fine. Am extending a class with eventemitter3 like this:

function MyClass(){...}
MyClass.prototype = Object.create(EventEmitter.prototype);
MyClass.prototype.constructor = MyClass;

MyClass.prototype.someMethod = function(){
    this.emit('notify');
}

Now listening to the notify event throws an error:

var mv = new MyClass();
mc.on('notify', handleNotify); 
// -> Uncaught TypeError: Cannot read property 'notify' of undefined
// ( _events is undefined in EventEmitter.prototype.on )

Yes, you have to invoke the super constructor in your child constructor.
Please read the release notes.

👍 Thank you, I didn't see the release notes.