new EventEmitter()
Provides observer pattern for basic eventing. Directly uses Backbone.Events
- Source:
Methods
-
listenTo(other, event, callback)
-
An inversion-of-control version of
on
. Tell this object to listen to an event in another object keeping track of what it's listening to.Parameters:
Name Type Description other
Object The object to listen to event
String Name of the event to listen to callback
Function Callback to execute when the event is triggered - Source:
-
off(event, callback, context)
-
Remove one or many callbacks. If
context
is null, removes all callbacks with that function. Ifcallback
is null, removes all callbacks for the event. Ifevents
is null, removes all bound callbacks for all events.Parameters:
Name Type Argument Description event
String <optional>
Name of the event that is being listened to callback
Function <optional>
Callback to remove context
Object <optional>
Remove callbacks with the specified context - Source:
-
on(event, callback, context)
-
Bind one or more space separated events, or an events map, to a
callback
function. Passing"all"
will bind the callback to all events fired.Parameters:
Name Type Argument Description event
String Event to listen to callback
Function Callback to execute when the event is triggered context
Object <optional>
The value of this
when the callback runs- Source:
-
once(event, callback, context)
-
Bind events to only be triggered a single time. After the first time the callback is invoked, it will be removed.
Parameters:
Name Type Argument Description event
String Name of the event to listen to callback
Function Callback to execute when the event is triggered context
Object <optional>
The value of this
when the callback runs- Source:
-
stopListening(other, event, callback)
-
Tell this object to stop listening to either specific events or to every object it's currently listening to.
Parameters:
Name Type Argument Description other
Object <optional>
The object that is being listened to event
String <optional>
Name of the event that is being listened to callback
Function <optional>
Callback to remove - Source:
-
trigger(event, args)
-
Trigger one or many events, firing all bound callbacks. Callbacks are passed the same arguments as
trigger
is, apart from the event name (unless you're listening on"all"
, which will cause your callback to receive the true name of the event as the first argument).Parameters:
Name Type Argument Description event
String Name of the event to trigger args
Mixed <optional>
<repeatable>
Arguments to pass to callback functions - Source: