emadurandal
10/12/2013 - 5:05 AM

Function.prototype.bindの、複数の引数を配列で渡せるバージョン ref: http://qiita.com/emadurandal/items/b40b2083e863196c3264

Function.prototype.bindの、複数の引数を配列で渡せるバージョン ref: http://qiita.com/emadurandal/items/b40b2083e863196c3264

Object.defineProperty(
Function.prototype,
'bindApply', 
{
value : function( thisObject, argumentsArray ) {
return Function.prototype.bind.apply(this, [thisObject].concat(argumentsArray));
},
writable : false,
enumerable : false,
configurable : false
}
);

function getBoundFuncByBindApply(obj, func, argv) {
return func.bindApply(obj, argv);
}

function getBoundFuncByMySelf(obj, func, argv) {
return Function.prototype.bind.apply(func, [obj].concat(argv));
}

function showThis(arg1, arg2){
alert(this + arg1 + arg2);
}

var foo = getBoundFuncByBindApply("Thisです:", showThis, [" Foo "," Boo "]); // どちらでもOK
var foo = getBoundFuncByMySelf("Thisです:", showThis, [" Foo "," Boo "]); // どちらでもOK

foo();