1.面向切面的概念解读
简称AOP
2.面向切面的代码实战
// 统计一下当前的所有函数谁耗时最长
function test(num){
alert(2);
return "me test";
}
Function.prototype.before = function(fn){
var __self = this;
return function(){
fn.apply(this,arguments);
__self.apply(__self,arguments);
}
};
Function.prototype.after = function(fn){
// after 先执行本身this,再执行回调
let __self = this;
return function(){
__self.apply(__self,arguments);
fn.apply(this,arguments);
}
}
test.after(function(){
alert(3);
}).before(function(){
alert(1);
})();