跳到主要內容
版本:23.11.1

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 以讓您可以鏈式呼叫方法。