Skip to content
Akin C edited this page Mar 1, 2019 · 10 revisions

Welcome to the Javascript-stack-trace-with-caller- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


ERROR: No image found!

The file "stack.js" contains a recursive function which could, if activated, shut down your browser. Please, use the project with caution and only if you know what you are doing.


Javascript offers the property caller which could be used to determine the function in which it was applied. Like the following example should show:

var list = [];

//"a" uses the property "caller"
function a()
{
        //Iterates through all the functions in which function "a" exists
	for(var f = a.caller; f; f = f.caller)
	{
		list.push(f);
	}
}

//"b" calls "a"
function b()
{
	a()
}

//"c" calls "b"
function c()
{
	b();
}

//Calling sequence is c->b->a
c();

/*
======
Output
======
[ƒ, ƒ]
0: ƒ b()
1: ƒ c()
length: 2
*/
console.log(list);

This ability could be useful for implementing a Stack Trace, but that should be done with caution.

The reason for this, it seems, would be that the feature caller is not heavily supported anymore.

Also its usefulness in recursion should not be given(check function BuggyCall in file "stack.js").

Content

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.

ERROR: No image found!

  • 🅱️ utton "WORKS" activates a functional simple Stack Trace

  • 🅱️ utton "BUGGY" activates a recursive function, but efore that its call has to be activated within the file "stack.js"

  • By pressing one of the described buttons, the "RESULT" area informs the user the needed steps to see the results.

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.

Clone this wiki locally