EventTarget

EventTarget

EventTarget is implemented by objects that can receive events and may have listeners for them.

Constructor

new EventTarget()

Example
function MyObject() {
    EventTarget.apply(this, arguments);
}
MyObject.prototype = Object.create(EventTarget.prototype);

Methods

fire(event) → {EventTarget}

Sends an event to all listeners

Parameters:
Name Type Description
event Object

Event passed to the listeners

Properties
Name Type Description
type string

The name of the event

has(type) → {boolean}

Test if there are any listeners bound to a certain event type

Parameters:
Name Type Description
type string

Type of event to test for

off(type, listener) → {EventTarget}

Removes a listener for a certain event type

Parameters:
Name Type Description
type string

Type of event listener to remove

listener function

Listener to remove

on(type, listener) → {EventTarget}

Registers a new listener for a certain event type

Parameters:
Name Type Description
type string

Type of event listener to add

listener function

Listener to add