-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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".
The user interaction part could look like the content as seen below by starting "index.html" in a web browser and interacting with its features.
- The input field expect a number value which should represent the length of the Fibonnacci sequence
🅱️ utton "CALCULATE" starts calculating the sequence- After pressing "CALCULATE" the result should be shown
To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.
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