function Event(type, fn) {
this.cache = {};
this.add = (type, fn) => {
if (this.cache[type]) {
this.cache[type].push(fn)
} else {
this.cache[type] = [fn];
}
}
this.on = (type) => {
this.cache[type] && this.cache[type].forEach(listener => {
listener();
});
}
this.off = (type, fn) => {
if (this.cache[type]) {
const index = this.cache[type].findIndex(item => item === fn);
this.cache[type].splice(index, 1)
console.log("type move");
}
}
}
const event = new Event();
const clickFn = () => {
console.log("click on");
}
event.add("click", clickFn)
event.on("click");
event.off("click", clickFn);
console