-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Akin C edited this page May 13, 2018
·
11 revisions
This repository is part of a larger project!
Javascript`s property arguments.callee is able to refer to the function in which it is called. This allows the developer to use it for recursive purposes, as the following example should show:
var myName = "Incrementis";
var letters = [];
//Divides the string into letters and saves them into an array
function Divide(name, position, container)
{
if(position === 0)
{
container.push(name[0]);
}
else
{
//Call of the function "Divide" within "Divide"
arguments.callee(name, position-1, container);
container.push(name[position]);
}
}
//First Call
Divide(myName, myName.length-1, letters);
//Outputs: ["I", "n", "c", "r", "e", "m", "e", "n", "t", "i", "s"]
console.log(letters);
📕 It seems that it is recommended to avoid using arguments.callee. Explained reasons for this should be found here, within the item "Making eval and arguments simpler"
STILL IN WORK!
This knowledge was gained:
- Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
Sources:
-
Javascript`s property arguments.callee by MDN Web docs
-
Get number of digits with JavaScript asked by bit4fox and answered by VisioN
-
Two ways of clearing an array in JavaScript by Dr. Axel