diff --git a/src/Eventable.js b/src/Eventable.js index cb3433f4d..d6d584f30 100644 --- a/src/Eventable.js +++ b/src/Eventable.js @@ -36,7 +36,7 @@ class Eventable { on (eventType, listener) { // if this type of event was never bound - if (!(eventType in this)) { + if (this[eventType]) { this[eventType] = [listener]; } else { @@ -50,7 +50,11 @@ class Eventable { const index = eventList? indexOf(eventList, listener) : -1; if (index !== -1) { - this[eventType].splice(index, 1); + eventList.splice(index, 1); + } + let undef; + if (eventList && eventList.length === 0 || undef === listener) { + this[eventType] = undef; } } }