你知道什么是aop吗
function test(argument){
alert(2)
}
Function.prototype.before = function(fn){
var _self = this;
return function(){
fn.apply(_self, arguments);
_self.apply(_self, arguments);
}
fn();
return _self.apply(this, arguments)
}
Function.prototype.after = function (fn) {
//body 先执行本身 在执行回调
var _self = this;
return function(){
_self.apply(this, arguments);
fn.apply(this, arguments);
}
}
test.before(function(){
alert(1)
return 'me test'
})
//1. test被执行了两次
//2. 将before和after作为中转站
//3. 挂载self的到fn上面
最后更新于