| mojo.Messaging.subscribe = function( | topic, | | targetObj, | | targetFunc | ) |
|
Attaches a listener to a message topic--Use returned handle to unsubscribe.
Parameters
| topic | {string} |
| targetObj | {object} |
| targetFunc | {string} |
Returns
{object} handle
Example
// subscribe an object's function to a message topic
var test = {dialog: function(msg) {
if (!msg) msg = "test";
alert(msg);
}}
var handle = mojo.Messaging.subscribe("someTopic", test, "dialog");
// invoke dialog function by publishing message topic
mojo.Messaging.publish("someTopic");
// invoke dialog function, and pass in a parameter
mojo.Messaging.publish("someTopic", ["hello world"]);