Skip to content

Commit

Permalink
[fix minor] Set this.event for both wildcard and non-wildcard events.…
Browse files Browse the repository at this point in the history
… Pass arguments to .onAny() handlers. A couple of minor whitespace changes for consistency
  • Loading branch information
indexzero committed Jul 27, 2011
1 parent cfa521d commit 7265ce7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/eventemitter2.js
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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]);
Expand All @@ -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];
Expand Down

0 comments on commit 7265ce7

Please sign in to comment.