EventEmitter 类
🌐 EventEmitter class
许多 Puppeteer 类扩展的 EventEmitter 类。
🌐 The EventEmitter class that many Puppeteer classes extend.
语法
🌐 Signature
export declare class EventEmitter<Events extends Record<EventType, unknown>> implements CommonEventEmitter<EventsWithWildcard<Events>>
Implements: CommonEventEmitter<EventsWithWildcard<Events>>
附注
🌐 Remarks
这使你可以监听 Puppeteer 类触发的事件并相应地采取行动。因此,你大多数时候会使用 on 和 off 来绑定和解绑事件监听器。
🌐 This allows you to listen to events that Puppeteer classes fire and act accordingly. Therefore you'll mostly use on and off to bind and unbind to event listeners.
这个类的构造函数被标记为内部。第三方代码不应直接调用构造函数或创建继承 EventEmitter 类的子类。
🌐 The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the EventEmitter class.
方法
🌐 Methods
方法 🌐 Method | 修饰符 🌐 Modifiers | 描述 🌐 Description |
|---|---|---|
| emit(type, event) | 触发事件并调用任何关联的监听器。 🌐 Emit an event and call any associated listeners. | |
| listenerCount(type) | 获取给定事件的监听器数量。 🌐 Gets the number of listeners for a given event. | |
| off(type, handler) | 从触发中删除事件监听器。 🌐 Remove an event listener from firing. | |
| on(type, handler) | 绑定事件监听器以在事件发生时触发。 🌐 Bind an event listener to fire when an event occurs. | |
| once(type, handler) | 像 🌐 Like | |
| removeAllListeners(type) | 移除所有监听器。如果提供了事件参数,它将只移除该事件的监听器。 🌐 Removes all listeners. If given an event argument, it will remove only listeners for that event. |