1The apply() method accepts arguments in an array:
2
3var arr = [6, 89, 3, 45];
4var maximus = Math.max.apply(null, arr); // returns 89
1Function.prototype.construct = function(aArgs) {
2 let oNew = Object.create(this.prototype);
3 this.apply(oNew, aArgs);
4 return oNew;
5};
6
1Function.prototype.construct = function (aArgs) {
2 let fNewConstr = new Function("");
3 fNewConstr.prototype = this.prototype;
4 let oNew = new fNewConstr();
5 this.apply(oNew, aArgs);
6 return oNew;
7};
8
1function myFunc(p1, p2, pN)
2{
3 // here "this" equals myThis
4}
5let myThis = {};
6
7// call myFunc using myThis as context.
8// destructure array to function arguments.
9myFunc.apply(myThis, ["param1", "param2", "paramN"]);