Common subexpression in emit.

This commit is contained in:
Herbert Vojčík authored and Ryan Dahl committed 2010-09-17 11:20:52 -07:00
1 parent 1375b8ed39
commit 8dcd6dccab
1 file changed
+7 -9
+7 -9
View File
@@ -18,27 +18,25 @@ EventEmitter.prototype.emit = function (type) {
}
if (!this._events) return false;
if (!this._events[type]) return false;
var handler = this._events[type];
if (!handler) return false;
if (typeof this._events[type] == 'function') {
if (typeof handler == 'function') {
if (arguments.length <= 3) {
// fast case
this._events[type].call( this
, arguments[1]
, arguments[2]
);
handler.call(this, arguments[1], arguments[2]);
} else {
// slower
var args = Array.prototype.slice.call(arguments, 1);
this._events[type].apply(this, args);
handler.apply(this, args);
}
return true;
} else if (isArray(this._events[type])) {
} else if (isArray(handler)) {
var args = Array.prototype.slice.call(arguments, 1);
var listeners = this._events[type].slice(0);
var listeners = handler.slice();
for (var i = 0, l = listeners.length; i < l; i++) {
listeners[i].apply(this, args);
}