Browse Source

events: Handle emit before constructor call

v0.9.12-release
isaacs 12 years ago
parent
commit
d345c1173a
  1. 3
      lib/events.js
  2. 1
      test/simple/test-event-emitter-subclass.js

3
lib/events.js

@ -73,6 +73,9 @@ EventEmitter.prototype.emit = function(type) {
} }
} }
if (!this._events)
this._events = {};
handler = this._events[type]; handler = this._events[type];
if (typeof handler === 'undefined') if (typeof handler === 'undefined')

1
test/simple/test-event-emitter-subclass.js

@ -27,6 +27,7 @@ var util = require('util');
util.inherits(MyEE, EventEmitter); util.inherits(MyEE, EventEmitter);
function MyEE(cb) { function MyEE(cb) {
this.emit('bar');
this.on('foo', cb); this.on('foo', cb);
process.nextTick(this.emit.bind(this, 'foo')); process.nextTick(this.emit.bind(this, 'foo'));
EventEmitter.call(this); EventEmitter.call(this);

Loading…
Cancel
Save