ch.EventEmitter
Description
Event Emitter Class for the browser.
How-to
// Create a new instance of EventEmitter.
var emitter = new ch.EventEmitter();
// Inheriting from EventEmitter.
ch.util.inherits(Widget, ch.EventEmitter);
Methods
-
event
- String : The name of the event you want to emit. -
var_args
- Object : Data to pass to the listeners. -
event
- String : The event name. -
event
- String : Event name. -
listener
- Function : Listener function. -
event
- String : The event name to subscribe. -
listener
- Function : Listener function. -
once
- Boolean : Indicate if a listener function will be called only one time. -
event
- String : Event name. -
listener
- Function : Listener function.
.emit(event, var_args)
Execute each item in the listener collection in order with the specified data.
// Will emit the 'ready' event with 'param1' and 'param2' as arguments.
widget.emit('ready', 'param1', 'param2');
.getListeners(event) → {Array}
Returns all listeners from the collection for a specified event.
// Returns listeners from 'ready' event.
widget.getListeners('ready');
.off(event, listener) → {Object}
Removes a listener from the collection for a specified event.
// Will remove event listener to 'ready' event.
widget.off('ready', listener);
.on(event, listener, once)
Adds a listener to the collection for a specified event.
// Will add an event listener to 'ready' event.
widget.on('ready', listener);
.once(event, listener) → {Object}
Adds a listener to the collection for a specified event to will execute only once.
// Will add an event handler to 'contentLoad' event once.
widget.once('contentLoad', listener);