dojo/on is a is a general-purpose event handler module for DOM nodes and other event emitting objects.

require([

"dojo/on",

"dojo/query"

], function(on) {

on(trgtNode, "trgtEvt", function() {

// handle the event

});

});

Notes

If event delegation is used, remember to require dojo/query or it won’t work.

See dojo/Evented base class for objects that emit their own events.

dojo/aspect - Aspect Oriented Programming (AOP)

dojo/aspect provides AOP to attach additional functionality to existing methods.

Using dojo/aspect

define([

"dojo/store/Memory",

"dojo/aspect"

], function(Memory, aspect) {

var someData = [

{id:0, name:"Zero"},

{id:1, name:"One"}];

var store =

new Memory({data:someData});

aspect.before(store, "get",

function(arg) {

// this is called before

// any get call

console.log(

"store.get(" + arg + ")");

});

// this will execute the

// the advising function, then

// the original get method

store.get(1);

});

Notes

If you are connecting to DOM Events rather than regular JS objects and functions, use dojo/on rather than dojo/aspect .

Use lang.hitch to bind a different context to the listener function.

Available DOM events

The following properties are available for all events: target, currentTarget, pageX/Y, layerX/Y, fromElement, toElement, charCode, charOrCode.