EventEmitter.on() 方法
繫結一個事件監聽器,當事件發生時觸發。
簽名
class EventEmitter {
on<Key extends keyof EventsWithWildcard<Events>>(
type: Key,
handler: Handler<EventsWithWildcard<Events>[Key]>,
): this;
}
參數
參數 | 類型 | 描述 |
---|---|---|
type | Key | 您想要監聽的事件類型。可以是字串或符號。 |
handler | Handler<EventsWithWildcard<Events>[Key]> | 當事件發生時要呼叫的函式。 |
回傳
this
this
以啟用方法鏈式調用。