JSFiddle - React, Tailwind, and code Playground
aspect context example
by kfranqueiro
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8/dijit/themes/claro/document.css">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8/dijit/themes/claro/claro.css">
JavaScript
require([
"dojo/aspect",
"dojo/domReady!"
], function(aspect){
var foo = {
greeting: "Hi",
statement: "I has an aspect.",
firstName: "Ken",
lastName: "Franqueiro",
log: function(){ console.log(this.firstName); }
};
// before advice: execution context preserved, no hitch needed
aspect.before(foo, "log", function(){ console.log(this.greeting); });
// after advice: execution context preserved, no hitch needed
aspect.after(foo, "log", function(){ console.log(this.lastName); });
// around advice: execution context preserved into returned function,
// but calling original function needs to preserve context
aspect.around(foo, "log", function(originalLog){
return function(){
console.log(this.statement);
originalLog.call(this);
};
});
foo.log();
});