mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
Common subexpression in emit.
This commit is contained in:
1 parent
1375b8ed39
commit
8dcd6dccab
1 file changed
+7
-9
+7
-9
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user