Browse Source

Common subexpression in emit.

v0.7.4-release
Herbert Vojčík 14 years ago
committed by Ryan Dahl
parent
commit
3e0a8f3ad8
  1. 16
      lib/events.js

16
lib/events.js

@ -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);
}

Loading…
Cancel
Save