javascript apply code example
Example 1: apply() js
The apply() method accepts arguments in an array:
var arr = [6, 89, 3, 45];
var maximus = Math.max.apply(null, arr);
Example 2: apply js
Function.prototype.construct = function(aArgs) {
let oNew = Object.create(this.prototype);
this.apply(oNew, aArgs);
return oNew;
};
Example 3: 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 4: javascript apply
function myFunc(p1, p2, pN)
{
}
let myThis = {};
myFunc.apply(myThis, ["param1", "param2", "paramN"]);