Open qiuhongbingo opened 4 years ago
class Notify { constructor() { this.subscribers = [] } add(handler) { this.subscribers.push(handler) } emit() { this.subscribers.forEach(subscriber => subscriber()) } } let notify = new Notify() notify.add(() => console.log('emit 1')) notify.add(() => console.log('emit 2')) notify.emit() // emit 1、emit 2