How to I get a backtrace in Javascript?
Ideal features:
Can this be done in standard ECMAScript?
If not, can it be done in the common web browser dialects?
Thanks.
Thanks for your suggestions.
My dialect doesnot support arguments.caller
or arguments.callee
.
I can do this:
try {
let x = null;
x .foo ();
}
catch (e) {
debug (dump (e.stack));
}
Which gets me the information as a string, which is okay for at-a-glance, but it would be a great help to walk e.stack
. Does it have a standard form?
Thanks again.
A stack trace is a list of the functions, in order, that lead to a given point in a software program. A stack trace is essentially a breadcrumb trail for your software. You can easily see the stack trace in JavaScript by adding the following into your code: console. trace();
Definition and Usage The trace() method displays a trace that show how the code ended up at a certain point.
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.
It's a function call. It goes to the call stack.
In my debugging experience, I always use this
(function () { console.log(new Error().stack); })();
As the comments below suggested, the readers should prefer: console.log(new Error().stack);
Another way is to use
console.trace();
source: 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