Class comb.plugins.Broadcaster
Defined in: Broadcaster.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Plugin to allow a class to easily broadcast events
|
Method Attributes | Method Name and Description |
---|---|
broadcast(name, args)
Broadcasts an event from an object
|
|
listen(topic, callback)
Listens to a broadcasted event
Simimlar to comb.listen
|
|
unListen(handle)
Disconnects a listener
Similar to comb.unListen
|
Class Detail
comb.plugins.Broadcaster()
Plugin to allow a class to easily broadcast events
var Mammal = define(comb.plugins.Broadcaster, { instance : { constructor: function(options) { options = options || {}; this.super(arguments); this._type = options.type || "mammal"; }, speak : function() { var str = "A mammal of type " + this._type + " sounds like"; this.broadcast("speak", str); this.onSpeak(str); return str; }, onSpeak : function(){} } }); var m = new Mammal({color : "gold"}); m.listen("speak", function(str){ //called back from the broadcast event console.log(str); }); m.speak();
Method Detail
broadcast(name, args)
Broadcasts an event from an object
- Parameters:
- name
- the name of the event to broadcast
- {Object|String|Function|Date|Number} args Optional
- variable number of arguments to pass to listeners, can be anything
{Array}
listen(topic, callback)
Listens to a broadcasted event
Simimlar to comb.listen
- Parameters:
- {String} topic
- the topic to listen to
- {Function} callback
- the function to callback on event publish
- Returns:
- {Array} handle to disconnect a topic
unListen(handle)
Disconnects a listener
Similar to comb.unListen
- Parameters:
- handle
- disconnect a handle returned from Broadcaster.listen