Class EventDispatcher<TEventMap>

JavaScript events for custom objects

// 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();

Type Parameters

  • TEventMap extends {} = {}

Hierarchy (view full)

Implemented by

Constructors

Methods

  • Adds a listener to an event type.

    Type Parameters

    • T extends string

    Parameters

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    Returns void

  • Fire an event type.

    Type Parameters

    • T extends string

    Parameters

    Returns void

  • Checks if listener is added to an event type.

    Type Parameters

    • T extends string

    Parameters

    Returns boolean

  • Type Parameters

    • T extends string

    Parameters

    Returns boolean

  • Removes a listener from an event type.

    Type Parameters

    • T extends string

    Parameters

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    Returns void