Skip to content
Akin C edited this page May 13, 2018 · 11 revisions

Welcome to the Javascript-recursion-with-arguments.callee- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT 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!

Clone this wiki locally