dojo.connect()

Deprecated.

Dojo versions prior to 1.7 used dojo.connect() for event handling and advice. But it’s functionality has been replaced by dojo/on module and the dojo/aspect module’s after() method.

Events

As of Dojo 1.7, the preferred way of handling events is to use the new lightweight dojo/on module.

For compatibility reasons, the dojo.connect api’s will remain fully supported through remaining 1.x releases, but will likely be removed in Dojo 2.0. Migration from connect() to on() should be straightforward as the api signature is very similar.

Old code like:

var handle = dojo.connect(node, "onclick", callback);
...
dojo.disconnect(handle);

should be converted to:

require(["dojo/on"], function(on){
  var handle = on(node, "click", callback);
  ...
  handle.remove();
});
Note that:
  • the “on” prefix was dropped, and “onclick” became “click”
  • the “handle” has a remove() method, rather than there being a function like dojo.disconnect()

Advice

The preferred way of handling after advice is to use the new lightweight dojo/aspect’s after() method.

Old code:

var handle = dojo.connect(myInstance, "execute", callback);
...
dojo.disconnect(handle);

is changed to

require(["dojo/aspect"], function(aspect){
    aspect.after(myInstance, "execute", callback);
    ...
    handle.remove();
});

Note that callback() should not return a value, because if it did the returned value would be reported as the value that myInstance.execute() appeared to return, which is not what dojo.connect() did.

Table of Contents

Error in the documentation? Can’t find what you are looking for? Let us know!