Created
October 3, 2011 10:02
-
-
Save nbqx/1258806 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
| #target InDesign | |
| Function.prototype.before = function(){ | |
| var fn = undefined; | |
| var args = []; | |
| for(var i=0; i<arguments.length; i++){ | |
| if(i!=arguments.length-1){ | |
| args.push(arguments[i]); | |
| }else{ | |
| fn = arguments[i]; | |
| } | |
| } | |
| //実行するまえになにかを挟む | |
| if(fn!=undefined){ | |
| fn.apply(this); | |
| } | |
| //引数を追加してるよ => これをfn.applyで実行したいよね | |
| args.push(3); | |
| //本体を実行 | |
| return this.apply(this,args); | |
| }; | |
| var fn = function(a,b,c){return a+b+c}; | |
| alert(fn.before(1,2,function(){ | |
| alert('実行する前'); | |
| })); | |
| //delete演算子でbeforeを消してキレイにしとく | |
| delete Function.prototype.before; //trueかえるよ | |
| alert(Function.prototype.before); //undefinedのはず |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment