Created
November 29, 2012 10:33
-
-
Save kjelelokk/4168102 to your computer and use it in GitHub Desktop.
Dojo aspects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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