简单模拟发布订阅模式之on、once、off、emit、clear
class eventBus {
constructor() {
this.event = {
}
}
on(key, fn) {
Array.isArray(this.event[key]) ? this.event[key].push(fn) : this.event[key] = [fn]
}
once(key, fn) {
let vm = this
function curOnce() {
vm.emit(key, fn)
vm.off