1.0.0 • Published 3 years ago

@antan/eventemitter v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

一个简单的 EventEmitter

🏠 首页

安装

npm install

API

const emitter = new EventEmitter(isStrict: boolean);

isStrict 默认为false,用于on和off方法中判断是否相同监听器。

  • false 按照引用判断是否相同
  • true 调用toString后根据生成的字符串判断是否相同

on

添加事件监听器

emitter.on(eventName: string | Symbol, listener: Function)

emit

触发事件

emitter.emit(eventName: string | Symbol, data: any)

off

删除事件监听器

emitter.off(eventName: string | Symbol, listener: Function)

allOff

删除指定时间类型的所有事件监听器

emitter.allOff(eventName: string | Symbol)

Author

👤 banzheshenghuo

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator