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);
})();
本文介绍面向切面编程(AOP)的概念,并通过JavaScript示例演示如何在代码中实现函数执行前后的操作,以此来统计函数执行时间。
5816

被折叠的 条评论
为什么被折叠?



