Skip to main content
Version: 23.10.1

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 类触发的事件并采取相应的行动。因此,你主要使用 onoff 来绑定和取消绑定到事件监听器。

¥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

方法

修饰符

描述

emit(type, event)

触发事件并调用任何关联的监听器。

listenerCount(type)

获取给定事件的监听器数量。

off(type, handler)

从触发中删除事件监听器。

on(type, handler)

绑定事件监听器以在事件发生时触发。

once(type, handler)

on 类似,但监听器只会被触发一次,然后就会被删除。

removeAllListeners(type)

删除所有监听器。如果给定事件参数,它将仅删除该事件的监听器。