mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
23 lines
532 B
JavaScript
23 lines
532 B
JavaScript
export default class Events {
|
|
constructor(art) {
|
|
this.art = art;
|
|
this.destroyEvents = [];
|
|
this.proxy = this.proxy.bind(this);
|
|
}
|
|
|
|
proxy(target, name, callback, option = {}) {
|
|
if (Array.isArray(name)) {
|
|
name.forEach(item => this.proxy(target, item, callback, option));
|
|
}
|
|
|
|
target.addEventListener(name, callback, option);
|
|
this.destroyEvents.push(() => {
|
|
target.removeEventListener(name, callback, option);
|
|
});
|
|
}
|
|
|
|
destroy() {
|
|
this.destroyEvents.forEach(event => event());
|
|
}
|
|
}
|