Skip to content

Commit

Permalink
Refact for remove all listeners and return
Browse files Browse the repository at this point in the history
  • Loading branch information
hotoo committed Aug 17, 2014
1 parent 334aa1b commit 2d0c1a0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions evt.js
Expand Up @@ -17,29 +17,29 @@ Event.prototype = {
var me = this;
var listeners = me._;

// Remove *all* events
if (listeners){

// Remove *all* events
if (!(eventName || handler)) {
me._ = {};
return me;
}

var list = listeners[eventName];
if (list) {
if (handler) {
for (var i = list.length - 1; i >= 0; i--) {
if (list[i] === handler) {
list.splice(i, 1);
break;
} else {

var list = listeners[eventName];
if (list) {
if (handler) {
for (var i = list.length - 1; i >= 0; i--) {
if (list[i] === handler) {
list.splice(i, 1);
break;
}
}
}
else {
delete listeners[eventName];
}
}
else {
delete listeners[eventName];
}
}

}
}

return me;
Expand Down

0 comments on commit 2d0c1a0

Please sign in to comment.