Calling a Function Using function.apply

Another way to invoke functions in JavaScript is using the .apply() method. The syntax for .apply() is as follows: functionName.apply(thisArg, [array]). "functionName" refers to the function being called. However, with .apply(), an array containing all values can be sent instead of individual arguments. Additionally, "thisArg" specifies the object that "this" references inside the invoked function.

Function.prototype.apply()

The apply() method calls the specified function with a given this value, and arguments provided as an array (or an array-like object).


Source: Mozilla, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
Creative Commons License This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.