Class: Signal

Signal

Signal provides an implementation of the Observer pattern. Functions can be bound to the Signal, and they will be called when the Signal is dispatched. This implementation allows for keeping scope.

When dispatch has an object passed to it, this is called the "payload" and will be passed as a parameter to the listener functions


new Signal()

Author:
  • derschmale <http://www.derschmale.com>

Members


hasListeners

Returns whether there are any functions bound to the Signal or not.

Methods


bind(listener [, thisRef])

Binds a function as a listener to the Signal

Parameters:
Name Type Argument Description
listener function

A function to be called when the function is dispatched.

thisRef Object <optional>

If provided, the object that will become "this" in the function. Used in a class as such:

Example
signal.bind(this.methodFunction, this);

dispatch( [payload])

Dispatches the signal, causing all the listening functions to be called.

Parameters:
Name Type Argument Description
payload <optional>

An optional object to be passed in as a parameter to the listening functions. Can be used to provide data.


unbind()

Removes a function as a listener.


unbindAll()

Unbinds all bound functions.