From d345c1173ac9c7ba861039707a142e187651f71d Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 2 Mar 2013 11:58:21 -0800 Subject: [PATCH] events: Handle emit before constructor call --- lib/events.js | 3 +++ test/simple/test-event-emitter-subclass.js | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/events.js b/lib/events.js index 4cfa740765..dd4fdf64e7 100644 --- a/lib/events.js +++ b/lib/events.js @@ -73,6 +73,9 @@ EventEmitter.prototype.emit = function(type) { } } + if (!this._events) + this._events = {}; + handler = this._events[type]; if (typeof handler === 'undefined') diff --git a/test/simple/test-event-emitter-subclass.js b/test/simple/test-event-emitter-subclass.js index a71a7c73c4..537b682088 100644 --- a/test/simple/test-event-emitter-subclass.js +++ b/test/simple/test-event-emitter-subclass.js @@ -27,6 +27,7 @@ var util = require('util'); util.inherits(MyEE, EventEmitter); function MyEE(cb) { + this.emit('bar'); this.on('foo', cb); process.nextTick(this.emit.bind(this, 'foo')); EventEmitter.call(this);