Class EventDispatcher<TEventMap>

事件派发类

interface MyEventMap {
start: {
message: string
}
}
// 将事件添加到自定义对象
class Car extends EventDispatcher<MyEventMap> {
start() {
this.dispatchEvent({type: 'start', message: 'vroom vroom!'});
}
}
// 订阅事件
const car = new Car();
car.addEventListener('start', (event) => {
console.log(event.message);
});
car.start();

Type Parameters

  • TEventMap extends {} = {}

Hierarchy (view full)

Constructors

Methods