diff --git a/src/events.js b/src/events.js index 09d30417d..6b6f255d0 100644 --- a/src/events.js +++ b/src/events.js @@ -1,14 +1,14 @@ export default class Events { constructor(art) { this.art = art; - this.destroys = []; + this.destroyEvents = []; this.proxy = this.proxy.bind(this); this.init(); } proxy(target, name, callback) { target.addEventListener(name, callback); - this.destroys.push(() => { + this.destroyEvents.push(() => { target.removeEventListener(name, callback); }); } @@ -16,4 +16,8 @@ export default class Events { init() { console.log('Events init'); } + + destroy() { + this.destroyEvents.forEach(event => event()); + } } diff --git a/src/index.js b/src/index.js index 627400adb..5be09af0a 100644 --- a/src/index.js +++ b/src/index.js @@ -90,7 +90,7 @@ class Artplayer extends Emitter { } destroy() { - this.events.destroys.forEach(destroy => destroy()); + this.events.destroy(); this.refs.$container.innerHTML = ''; instances.splice(instances.indexOf(this), 1); }