node-aspect
v1.0.5
Published
nodejs aop aspect
Downloads
27
Readme
如何安装
npm install node-aspect
如何使用
module.exexports = class Hello {
say(name) {
console.log(`hello ${name}`);
return name;
}
}
//import
const Aspect = require('node-aspect');
// create Aspect
let aspect = new Aspect('/**/test/**/*.js', `classes`, `name`);
//set [before, after, error, around] handler
aspect.before((name, aspect) => {
console.log(`before: ${name}`);
});
//start aop
aspect.aop();
const Hello = require('./Hello');
console.log(new Hello().say('Alone'));
// output:
before: Alone
hello Alone
Alone
API
handler(type
, handler
)
Set handler.
type
- (String) aop handler type:before
- (String) target method before called.after
- (String) target method after return called.error
- (String) target method error called.around
- (String) target method around called.
handler
- (Function) aop handler function:before
- {function(arguments
)} last arg is this Aspect.after
- {function(arguments
+this Aspect
+ctx
+result
)} last arg is this Aspect.error
- {function(arguments
+this Aspect
+ctx
+error
)} last arg is this Aspect.around
- {function(arguments
)} last arg is this Aspect.
Return this
aop()
start aop.