.call() .apply() this. MDN:
apply(), , call() , apply() .
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
, // this , , , ,
function applyOriginalThis(fn, parametersArray)
{
var p = parametersArray;
switch (p.length)
{
case 0: fn(); break;
case 1: fn(p[0]); break;
case 2: fn(p[0], p[1]); break;
case 3: fn(p[0], p[1], p[2]); break;
case 4: fn(p[0], p[1], p[2], p[3]); break;
case 5: fn(p[0], p[1], p[2], p[3], p[4]); break;
case 6: fn(p[0], p[1], p[2], p[3], p[4], p[5]); break;
case 7: fn(p[0], p[1], p[2], p[3], p[4], p[5], p[6]); break;
case 8: fn(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); break;
case 9: fn(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8]); break;
default: throw "Too many parameters.";
}
}
Of course, this will only work for the number of parameters you want to support. On the bright side, functions that take an excessive amount of parameters are the smell of code . In addition, if I'm not mistaken, this type of code was used in AngularJS 1.x as a performance optimization on .apply()(now I can not find the link).