同步操作将从 散漫的水元素/aspects-js 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
aspects-js
Use aspect in node js
Just install by npm
$ npm install --save aspects-js
You need require aspects-js at first of entry js file
require('aspects-js');
Add a js file to write a aspect.
First, you should require class Aspect
from aspects-js.
//file: testAspect.js
const { Aspect } = require('aspects-js');
Secondly, you should declare a class extends Aspect and implements property pointcut
and functions for join point.
//file: testAspect.js
class TestAspect extends Aspect {
get pointcut() { return '*.do*()' },
before() { console.log('this is for before join point') },
after() { console.log('this is for after join point') }
}
Then, you should exports a instance of your class which is extends Aspect
//file: testAspect.js
module.exports = new TestAspect();
At last, require your aspects at entry.js file
//file: entry.js
require('./testAspect.js');
Now, all classes when you required will be cut by all your aspects.
interface Aspect {
readonly pointcut: Pointcut | string;
after(joinPoint: JoinPoint, result: any, error: Error);
afterReturn(joinPoint: JoinPoint, result: any): any;
afterThrow(joinPoint: JoinPoint, error: Error): void;
before(joinPoint: JoinPoint):void;
around(joinPoint: JoinPoint): any;
}
class JoinPoint {
readonly type: Class;
readonly fun: Function;
readonly thisArg: any;
readonly target: any;
readonly args: any[];
proceed(...args: any[]): any;
}
class Pointcut {
constructor(pointcut: string);
matches(type: Class | Function): boolean;
}
"ClassName.FunctionName()"
"execution(ClassName.FunctionName())"
"within(ClassName)"
*
Match all word"*Service.do*()"
Match all methods which's name is start with "do" and in classes which's name is end with "Service"
?
Match one word"you?.do?()"
+
Or operate"within(Test1+Test2)"
Just match all methods in classes which's name is "Test1" or "Test2"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。