Class EventDispatcher

JavaScript events for custom objects

Example

var Car = function () {

    EventDispatcher.call( this );
    this.start = function () {

        this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );

    };

};

var car = new Car();
car.addEventListener( 'start', function ( event ) {

    alert( event.message );

} );
car.start();
source

src/core/EventDispatcher.js

Hierarchy

Index

Constructor methods

Methods

Constructor methods

constructor(): EventDispatcher

Creates eventDispatcher object. It needs to be call with '.call' to add the functionality to an object.

Returns

EventDispatcher

Methods

public addEventListener(type: string, listener: (event: any) => void)

Adds a listener to an event type.

Parameters

  • type: string

    The type of the listener that gets removed.

  • listener: (event: any) => void

    The listener function that gets removed.

public dispatchEvent(event: { type: string; target: any; })

Fire an event type.

Parameters

  • event: { type: string; target: any; }

public hasEventListener(type: string, listener: (event: any) => void)

Adds a listener to an event type.

Parameters

  • type: string

    The type of the listener that gets removed.

  • listener: (event: any) => void

    The listener function that gets removed.

public removeEventListener(type: string, listener: (event: any) => void)

Removes a listener from an event type.

Parameters

  • type: string

    The type of the listener that gets removed.

  • listener: (event: any) => void

    The listener function that gets removed.