This modules allows to dispatch event objects on custom JavaScript objects.
Main repository: eventdispatcher.js
Code Example:
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', function ( event ) {
alert( event.message );
} );
car.start();
Adds the given event listener to the given event type.
type
The type of event to listen to.
listener
The function that gets called when the event is fired.
Dispatches an event object.
event
The event that gets fired.
Returns true if the given event listener has been added to the given event type.
type
The type of event.
listener
The listener to check.
Returns: Whether the given event listener has been added to the given event type.
Removes the given event listener from the given event type.
type
The type of event.
listener
The listener to remove.