It's well know how to print a stack trace after catching an exception/error in Javascript. But what if you are not catching anything? You see something happening at a particular line in code, but you want to know what's the code path through which the control flow reached that line when that interesting thing happened. In other words, you want to know what's the stack trace (series of function calls, starting from beginning of the program), at that particular line of code.
It's quite easy. If you don't have an exception, create one. Then you can print the stack trace off of it. Like this (gist) ...
Saturday, August 20, 2011
Subscribe to:
Post Comments (Atom)
2 comments:
You can easily get a stack trace at any time by calling console.trace() in your Javascript or in the Firebug console.
here's a similar post: http://www.eriwen.com/javascript/js-stack-trace/
Great tip for when console is not available... but 'stack' doesn't appear to be a standard property (only on Mozilla?)
Post a Comment