Functiondojo.subscribe

<script src="../../js/dojo.js"></script>
defined in dojo/_base/connect.js

Attach a listener to a named topic. The listener function is invoked whenever the named topic is published (see: dojo.publish). Returns a handle which is needed to unsubscribe this listener.

Usage

function (/*String*/ topic, /*Object*/ context, /*String|Function*/ method) (view source)
parametertypedescription
topicString 
contextObjectScope in which method will be invoked, or null for default scope.
methodString|FunctionThe name of a function in context, or a function reference. This is the function that is invoked when topic is published.

Examples

Example 1

dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
dojo.publish("alerts", [ "read this", "hello world" ]);