example of js apply
Example 1: apply js
Function.prototype.construct = function (aArgs) {
let fNewConstr = new Function("");
fNewConstr.prototype = this.prototype;
let oNew = new fNewConstr();
this.apply(oNew, aArgs);
return oNew;
};
Example 2: javascript apply
function myFunc(p1, p2, pN)
{
// here "this" equals myThis
}
let myThis = {};
// call myFunc using myThis as context.
// destructure array to function arguments.
myFunc.apply(myThis, ["param1", "param2", "paramN"]);