JavaScript events for custom objects

Example

// Adding events to a custom object
class Car extends EventDispatcher {
start() {
this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
}
};
// Using events with the custom object
const car = new Car();
car.addEventListener( 'start', ( event ) => {
alert( event.message );
} );
car.start();

See

Hierarchy (view full)

Constructors

Methods

  • Fire an event type.

    Type Parameters

    • T extends "error"

    Parameters

    Returns void