Does anyone know how to get function call stack (backtrace) programatically in javascript?
is this even possible? if yes, how?
You can use Function. Caller to get the calling function.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With