Aspect Oriented Programming(AOP),面向切面编程,AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效果。 联想一下切面包、地板测量
function test() {
alert(2)
return 'hello world!'
}
Function.prototype.before = function(fn) {
var __self = this;
return function() {
fn.apply(this,arguments);
console.log('this:',this);
__self.apply(__self,arguments)
}
}
Function.prototype.after = function(fn) {
var __self = this;
return function() {
__self.apply(__self,arguments);
fn.apply(this,arguments)
}
}
test.before(function() {
alert(1)
}).after(function() {
alert(3)
})()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
← 基本错误捕获处理 前端基础面试题(一) →