<script type="text/javascript">
Function.prototype.before = function(beforefn){
var _self = this;
return function(){
beforefn.apply(this, arguments);
return _self.apply(this, arguments);
}
};
Function.prototype.after = function(afterfn){
var _self = this;
return function(){
var ret = _self.apply(this, arguments);
afterfn.apply(this, arguments);
return ret;
}
}
var func = function(){
console.log('执行函数....')
}
var exeFunc = func.before(function(){
console.log('before....');
}).after(function(){
console.log('after....')
});
exeFunc();
</script>
执行结果:
before....
执行函数....
after....