banzheshenghuo / EventEmitter

一个简单的 EventEmitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Welcome to EventEmitter 👋

Version Documentation Maintenance

一个简单的 EventEmitter

🏠 首页

安装

npm install @antan/eventemitter

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

About

一个简单的 EventEmitter

License:MIT License


Languages

Language:JavaScript 100.0%