Table of Contents

Javascript - Apply

About

apply permits to call a function stored in a variable specifying:

If you want to execute dynamically a string that stores javascript, you use the eval function.

Example

let dynamicCall = function(){
  
  console.log("The name property of this is: "+this.name);
  console.log("The arguments are: "+Object.values(arguments).join(", "));
  
}
console.log("First Call");
dynamicCall.apply( { name: "First Call" }, ["arg1", "arg2"] )

console.log("Second Call");
dynamicCall.apply( { name: "Second Call" }, ["arg3", "arg4"] )