Permalink
Browse files

[fix minor] Set this.event for both wildcard and non-wildcard events.…

… Pass arguments to .onAny() handlers. A couple of minor whitespace changes for consistency
  • Loading branch information...
1 parent cfa521d commit 7265ce70c53cf5dea02e1fdbdae37264d04bf9c9 @indexzero indexzero committed Jul 27, 2011
Showing with 8 additions and 5 deletions.
  1. +8 −5 lib/eventemitter2.js
View
@@ -166,14 +166,19 @@
this._events || this.init();
var type = arguments[0];
+ this.event = type;
+
// If there is no 'error' event listener then throw.
if (type === 'newListener') {
- if(!this._events.newListener) { return false; }
+ if (!this._events.newListener) { return false; }
}
// Loop through the *_allListenerFn* functions and invoke them.
if (this._all) {
+ var l = arguments.length;
+ var args = new Array(l - 1);
+ for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
for (i = 0, l = this._all.length; i < l; i++) {
this._all[i].apply(this, args);
}
@@ -193,7 +198,6 @@
var handler;
if(this.wildcard) {
- this.event = type;
handler = [];
var ns = type.split(this.delimiter);
searchListenerTree.call(this, handler, ns, this.listenerTree, 0);
@@ -203,10 +207,10 @@
}
if (typeof handler === 'function') {
- if(arguments.length === 1) {
+ if (arguments.length === 1) {
handler.call(this);
}
- else if(arguments.length > 1)
+ else if (arguments.length > 1)
switch (arguments.length) {
case 2:
handler.call(this, arguments[1]);
@@ -224,7 +228,6 @@
return true;
}
else if (handler) {
-
var l = arguments.length;
var args = new Array(l - 1);
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];

0 comments on commit 7265ce7

Please sign in to comment.