diff --git a/lib/events.js b/lib/events.js index 9eaa36ba68..bee1c6132f 100644 --- a/lib/events.js +++ b/lib/events.js @@ -84,7 +84,7 @@ EventEmitter.prototype.emit = function(type) { if (this.domain && this !== process) this.domain.enter(); - if (typeof handler == 'function') { + if (typeof handler === 'function') { switch (arguments.length) { // fast cases case 1: @@ -267,11 +267,14 @@ EventEmitter.prototype.removeAllListeners = function(type) { }; EventEmitter.prototype.listeners = function(type) { + var ret; if (!this._events || !this._events[type]) - return []; - if (typeof this._events[type] === 'function') - return [this._events[type]]; - return this._events[type].slice(); + ret = []; + else if (typeof this._events[type] === 'function') + ret = [this._events[type]]; + else + ret = this._events[type].slice(); + return ret; }; EventEmitter.listenerCount = function(emitter, type) {