Created
June 6, 2013 14:05
-
-
Save mutoo/5721751 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment