Skip to content

Instantly share code, notes, and snippets.

@kjelelokk
Created November 29, 2012 10:33
Show Gist options
  • Save kjelelokk/4168102 to your computer and use it in GitHub Desktop.
Save kjelelokk/4168102 to your computer and use it in GitHub Desktop.
Dojo aspects
require(['dojo/aspect'], function (aspect) {
var original = {
someMethod: function (arg1, arg2) {
console.warn('original.someMethod called:', arg1, arg2);
return 'Hello ' + arg1 + ' ' + arg2;
}
};
// aspect.before
aspect.before(original, 'someMethod', function (arg1, arg2) {
console.warn('aspect.before method called with arguments:', arg1, arg2);
});
// aspect.after
aspect.after(original, 'someMethod', function (arg1, arg2) {
console.warn('aspect.after method called with arguments:', arg1, arg2);
}, true);
// aspect.around
aspect.around(original, 'someMethod', function (originalMethod) {
return function (arg1, arg2) {
console.warn('aspect.around -> before method call, arguments:', arg1, arg2);
originalMethod(this, arguments);
console.warn('aspect.around -> after method call, arguments:', arg1, arg2);
};
});
original.someMethod('Ola', 'Normann');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment