In the dojo Javascript library, dojo/on and dojo/aspect are used as functions that listen to events.
However I don't see how they differ from one another. Can someone explain when you would use on and when you would use aspect?
In the dojo Javascript library, dojo/on and dojo/aspect are used as functions that listen to events.
However I don't see how they differ from one another. Can someone explain when you would use on and when you would use aspect?
dojo/on
is used for listening to events. dojo/aspect
is used to intercept calls to javascript functions.
With aspect, you can intercept a function call and do something before the function call, after, or both. With events, you are being notified that something occurred.
Technically, if the target object is not a domNode, dojo/on
ends up calling aspect.after(...)
In <=1.6, there was not a distinction and dojo.connect
was used. Functions were used to notify that an event occurred and there are still remnants of that in the code base. An example is using on with the click event on a dijit/Button
.
dojo/Evented
http://dojotoolkit.org/reference-guide/1.9/dojo/Evented.html