EventEmitter.once() 方法
与 on 类似,但监听器只会触发一次,之后会被移除。
签名
class EventEmitter {
once<Key extends keyof EventsWithWildcard<Events>>(
type: Key,
handler: Handler<EventsWithWildcard<Events>[Key]>,
): this;
}
参数
|
参数 |
类型 |
说明 |
|---|---|---|
|
type |
Key |
你希望监听的事件 |
|
handler |
Handler<EventsWithWildcard<Events>[Key]> |
事件发生时运行的处理器函数 |
返回值:
this
this 以便链式调用方法。