一个简单的 EventEmitter
🏠 首页
npm install @antan/eventemitter
const emitter = new EventEmitter(isStrict: boolean);
isStrict 默认为false,用于on和off方法中判断是否相同监听器。
- false 按照引用判断是否相同
- true 调用toString后根据生成的字符串判断是否相同
添加事件监听器
emitter.on(eventName: string | Symbol, listener: Function)
触发事件
emitter.emit(eventName: string | Symbol, data: any)
删除事件监听器
emitter.off(eventName: string | Symbol, listener: Function)
删除指定时间类型的所有事件监听器
emitter.allOff(eventName: string | Symbol)
👤 banzheshenghuo
- Github: @banzheshenghuo
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator