Created
July 6, 2011 16:26
-
-
Save mraleph/1067667 to your computer and use it in GitHub Desktop.
Make EventEmitter Crankshaft friendly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/events.js b/lib/events.js | |
index b681c10..3273391 100644 | |
--- a/lib/events.js | |
+++ b/lib/events.js | |
@@ -34,8 +34,8 @@ EventEmitter.prototype.setMaxListeners = function(n) { | |
this._events.maxListeners = n; | |
}; | |
- | |
-EventEmitter.prototype.emit = function(type) { | |
+EventEmitter.prototype.emit = function() { | |
+ var type = arguments[0]; | |
// If there is no 'error' event listener then throw. | |
if (type === 'error') { | |
if (!this._events || !this._events.error || | |
@@ -68,13 +68,17 @@ EventEmitter.prototype.emit = function(type) { | |
break; | |
// slower | |
default: | |
- var args = Array.prototype.slice.call(arguments, 1); | |
+ var l = arguments.length; | |
+ var args = new Array(l - 1); | |
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | |
handler.apply(this, args); | |
} | |
return true; | |
} else if (isArray(handler)) { | |
- var args = Array.prototype.slice.call(arguments, 1); | |
+ var l = arguments.length; | |
+ var args = new Array(l - 1); | |
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i]; | |
var listeners = handler.slice(); | |
for (var i = 0, l = listeners.length; i < l; i++) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment