Functiondojo.connect

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

Connects method to event, so that after event fires, method does too. All connected functions are passed the same arguments as the event function was initially called with. You may connect as many methods to event as needed.

Usage

function (/*Object*/ obj, /*String*/ event, /*Object*/ context, /*String|Function*/ method, /*Boolean*/ dontFix) (view source)
parametertypedescription
objObjectThe source object for the event function. Defaults to dojo.global if null. If obj is a DOM node, the connection is delegated to the DOM event manager (unless dontFix is true).
eventStringname of the event function in obj. I.e. identifies a property obj[event].
contextObjectThe object that method will receive as "this". If context is null and method is a function, then method inherits the context of event. If method is a string then context must be the source object object for method (context[method]). If context is null, dojo.global is used.
methodString|Functionreceives the same arguments as the event. See context argument comments for information on method's scope.
dontFixBooleanIf obj is a DOM node, set dontFix to true to prevent delegation of this connection to the DOM event manager.

Examples

Example 1

When obj.onchange(), do ui.update():

dojo.connect(obj, "onchange", ui, "update");
dojo.connect(obj, "onchange", ui, ui.update); // same

Example 2

Using return value for disconnect:

var link = dojo.connect(obj, "onchange", ui, "update");
...
dojo.disconnect(link);

Example 3

When onglobalevent executes, watcher.handler is invoked:

dojo.connect(null, "onglobalevent", watcher, "handler");

Example 4

When ob.onCustomEvent executes, customEventHandler is invoked:

dojo.connect(ob, "onCustomEvent", null, "customEventHandler");
dojo.connect(ob, "onCustomEvent", "customEventHandler"); // same

Example 5

When ob.onCustomEvent executes, customEventHandler is invoked with the same scope (this):

dojo.connect(ob, "onCustomEvent", null, customEventHandler);
dojo.connect(ob, "onCustomEvent", customEventHandler); // same

Example 6

When globalEvent executes, globalHandler is invoked with the same scope (this):

dojo.connect(null, "globalEvent", null, globalHandler);
dojo.connect("globalEvent", globalHandler); // same