Function.prototype.before = function (func){ var self = this; return function (){ if(func.apply(this, arguments) === false){ return false; } return self.apply(this, arguments); } } 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 a = function (){console.log('a function') }; var c = a.before(function (){console.log('before');}).after(function (){console.log('after')}) c();
原文:http://www.w3cfuns.com/thread-5597323-1-1.html