Function.prototype.before = function(func){
var __self =this;
return function(){
var ret = func.apply(this, arguments);
if(ret===false){
return false;
}
__self.apply(this, arguments);
return ret;
}
}
Function.prototype.after = function(func){
var __self =this;
return function(){
var ret = __self.apply(this, arguments);
if(ret===false){
return false;
}
func.apply(this, arguments);
return ret;
}
}
var f = function(){
console.log(1);
}
f = f.before(function(){
console.log(0);
});
f = f.after(function(){
console.log(2);
});
f(); // 0 \ 1 \ 2