From spec .
We need to take argArray and create what will be the argument to the object pseudo array.
Essentially
Function.prototype.apply = function apply (thisArg, argArray) {
var len = argArray.length;
var n = ToUint32(len);
var argList = [];
var index = 0;
var indexName;
var nextArg;
while (index < len) {
indexName = ToString(index);
nextArg = argArray[indexName];
argList.push(nextArg);
index++;
}
return this['[[Call]]'](func, thisArg, argList);
}
I skipped some of the type checks that occur, but this is essentially pretty close to what the specification specifies as implemented Function.prototype.apply. We create our own object and create argListbefore calling the function.
It is important to note. that the internal method named [[Call]]differs from Function.prototype.call.
source
share