API Docs for:
Show:

EventHandler Class

Constructor

EventHandler

()

Item Index

Methods

subscribe

(
  • event
  • callback
  • [subscriber]
)

Parameters:

  • event String

    Name of the event being subscribed to.

  • callback Function

    Function that will be called back when the specified event is triggered.

  • [subscriber] Object optional

    An optional parameter that specifies an object that's subscribing. When a function is subscribed with an object, that function will be called back with "this" set to the object.

trigger

(
  • event
  • [eventObject]
)

Triggers the event, calling all functions that subscribed to it.

Parameters:

  • event String

    The event to be triggered.

  • [eventObject] Object optional

    All functions that were subscribed to the specified event will be called with this as the argument.

unsubscribe

(
  • event
  • [callback]
  • [subscriber]
)

This is a multi-purpose method. See the example for all the ways it can be overloaded.

Parameters:

  • event Object
  • [callback] Object optional
  • [subscriber] Object optional

Example:

   //Unsubscribing all callbacks for a given event.
  eventHandler.unsubscribe('eventName');

  //Unsubscribing all callbacks subscribed by the object.
  eventHandler.unsubscribe(object);

  //Unsubscribing all callbacks an object made for the given event.
  eventHandler.unsubscribe('eventName', object);

  //Unsubscribing a callback that was subscribed with an object.
  eventHandler.unsubscribe('eventName', callback, object);

  //Unsubscribing a callback subscribed by itself.
  eventHandler.unsubscribe('eventName', callback);
  //The last method can't be used to unsubscribe callbacks which were subscribed with an object.