Skip to content

Instantly share code, notes, and snippets.

@nbqx
Created October 3, 2011 10:02
Show Gist options
  • Select an option

  • Save nbqx/1258806 to your computer and use it in GitHub Desktop.

Select an option

Save nbqx/1258806 to your computer and use it in GitHub Desktop.
#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