From 090ccbb68141778f9fed0b7c5ad25f4f276c7c90 Mon Sep 17 00:00:00 2001 From: Boris CERATI Date: Thu, 23 Apr 2020 13:35:39 +0200 Subject: [PATCH] fix[DETACH EVENT] Fix bug when detaching all events --- src/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 3d4123a..e106654 100644 --- a/src/index.js +++ b/src/index.js @@ -113,15 +113,22 @@ * @param {callback} callback - the callback to remove (undefined to remove all of them). */ detach: function(eventName, callback) { + if (callback === undefined) { + that.listeners[eventName] = []; + return true; + } + for (var k in that.listeners[eventName]) { if ( that.listeners[eventName].hasOwnProperty(k) && - (that.listeners[eventName][k].callback === callback || - callback === undefined) + that.listeners[eventName][k].callback === callback ) { that.listeners[eventName].splice(k, 1); + return this.detach(eventName, callback); } } + + return true; }, /**