var beforeAdvice =
new jsAspect.Advice.Before(function() {
console.log("joinPoint", "before");
}).withRegex("set.*");
var aspect =
new jsAspect.Aspect(beforeAdvice);Text
var obj = {
method1: function() {
return "doing Something";
}
};
aspect.applyTo(obj);
obj.method1();the problem is, that nobody did it (as far as I know)
transpile ES6 into ES5
https://babeljs.io/
Babylon.js parser into AST
plugins
1. create AST from source files (Babel)
2. parse aspects from aspects.js file
3. traverse AST and apply aspects
var aspects = [
{
joinpoint: Joinpoints.BEFORE,
pointcut: 'Test.myMethod',
advice: function advice() {
console.log('before advice');
}
}
];class Test {
myMethod() {
console.log('my method');
}
}
class Test {
myMethod() {
console.log('before advice');
console.log('my method');
}
}
var aspects = [
{
rule: 'after returning MyClass.get*',
advice: function advice(value) {
console.log('after advice');
console.log('context', this);
}
}
];join points - class method call
pointcuts - signatures with *
advices: Before, After, After returning, After throwing, Around
https://github.com/PatrikGallik/babel-plugin-transform-aop