-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Akin C edited this page Nov 3, 2017
·
20 revisions
This repository is part of a larger project!
The Javascript apply method is similar to the method call.
The big difference is the ability of apply to take an array of arguments.
This is important for example variadic functions or also known as variable-arity functions. An example for a variadic function could be one which calculates the sum of a series of numbers:
//Variadic Function
function calculateSum(listOfNumbers)
{
var sum = 0;
for(var i = 0; i < listOfNumbers.length; i++)
{
sum+=listOfNumbers[i];
}
return sum;
}
//Outputs Sum
calculateSum([1,2,3]);
STILL IN WORK!!!
This knowledge was gained:
-
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
-
Why would you pass 'null' to 'apply' or 'call'? asked by Antonio Pavicevac-Ortiz and answered by Christos