Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone know how to get function call stack (backtrace) programatically in javascript?

Tags:

javascript

Does anyone know how to get function call stack (backtrace) programatically in javascript?

is this even possible? if yes, how?

like image 464
fmsf Avatar asked Dec 09 '11 08:12

fmsf


People also ask

How to get name of the calling function in JavaScript?

You can use Function. Caller to get the calling function.

How does JavaScript call stack work?

A call stack is a mechanism for an interpreter (like the JavaScript interpreter in a web browser) to keep track of its place in a script that calls multiple functions — what function is currently being run and what functions are called from within that function, etc.

How can I check my browser stack trace?

You can easily see the stack trace in JavaScript by adding the following into your code: console. trace(); And you'll get an outputted stack trace.

What is stack overflow in js?

A stack overflow occurs when there is a recursive function (a function that calls itself) without an exit point. The browser (hosting environment) has a maximum stack call that it can accomodate before throwing a stack error.


1 Answers

This wasn't available at the time the question was asked but now all modern web browsers support console.trace(). Be aware that this feature is considered as non-standard. More about that here: https://developer.mozilla.org/en-US/docs/Web/API/Console.trace

like image 57
Jakub Macháček Avatar answered Oct 30 '22 21:10

Jakub Macháček