Events

Events

This class implements event handling.

Constructor

new Events()

Source:

Classes

Events

Methods

addEventListener()

Source:

Alias for on.

destroy()

Source:

Removes all event handlers.

dispatchEvent(…args) → {boolean}

Source:

This method is similar to emit() except that it returns false if an event handler stopped event processing.

Parameters:
Name Type Attributes Description
args * <repeatable>

Event arguments.

Returns:
  • The return value is false, if an event handler cancelled the event processing by returning something other than undefined. Otherwise, the return value is true.
Type
boolean

emit(…args)

Source:

Emit an event.

Event processing stops when the first event handler returns anything other than undefined.

If an event handler throws an exception, it is logged to the developer console.

Parameters:
Name Type Attributes Description
args * <repeatable>

Event arguments.

Returns:
  • Returns the value returned by the last event handler called or undefined.

hasEventListener(name, callback)

Source:

Returns true if the specified event handler is registered. If no callback is specified, true is returned if any event handler is installed for the given event name.

Parameters:
Name Type Description
name string

The event name.

callback function

The event callback.

off(name, callback)

Source:

Removes an event handler.

Parameters:
Name Type Description
name string

The event name.

callback function

The event callback.

on(name, callback)

Source:

Register an event handler. If the same event handler is already registered, an exception is thrown.

Parameters:
Name Type Description
name string

The event name.

callback function

The event callback.

once(name, callback) → {function}

Source:

Register an event handler to be executed once.

Parameters:
Name Type Description
name string

The event name.

callback function

The event callback.

Returns:
  • The return value is a function which can be called to remove the event subscription.
Type
function

removeEventListener()

Source:

Alias for off.

subscribe(name, callback) → {function}

Source:

Register an event handler. If the same event handler is already registered, an exception is thrown.

This method returns a function which removes the event handler.

Parameters:
Name Type Description
name string

The event name.

callback function

The event callback.

Returns:
  • The return value is a function which can be called to remove the event subscription.
Type
function