0

After using functionality from this question for debugging I am wondering is there a way to get the file name from which the function was invoked and may be the line.

May be I am asking for too much, but I know that in some of the languages it is possible.

If this is not possible can anyone mention why his functionality was not implemented?

I will try to rephrase the question, because I think I didn't make myself clear.

I have file.js in which on the 17-th line there is a declaration of the function:

...
function main()
{
   Hello();
}

I have another file test.js, where I define function hello

function Hello()
{
  ...
  which tells me the name of the file and a line in which the function which evoked it was defined
}

So for example if I will call main(), it will tell me file.js, 17 line

It has nothing to do with firebug

Community
  • 1
  • 1
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • Here's one reason: ["I had to be done in ten days or something worse than JS would have happened" - Brendan Eich](http://en.wikipedia.org/wiki/Brendan_Eich) – Alex Wayne Nov 14 '12 at 00:17
  • 2
    Use your browser's debugging tools. Both Chrome and Firefox (and probably even IE8+) have real JS debugging with stack traces – Phil Nov 14 '12 at 00:18
  • This is the [very first result](http://getfirebug.com/javascript) when googling "debug javascript". Not much effort on this question... – elclanrs Nov 14 '12 at 00:19

2 Answers2

1

You don't mention what browser you are using.

In Chrome what I would suggest is inserting a breakpoint on the first line of the function. Then reload the page (or otherwise trigger the function call). When execution pauses at the breakpoint, check the Call Stack section in Chrome's Developer tools - it will give you a stack back-trace of the flow of execution.

I'm sure Firebug offers something similar if not identical, it's just been a while since I used it.

Cheers

Madbreaks
  • 19,094
  • 7
  • 58
  • 72
1

If all your doing is debugging, hy not just use the debugger built into modern browsers?

debugger

That line is all you need. You can examine the callstack, inspect variable values, and even run code in the current scope.

Such functionality makes your request kind of unnecessary.

Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
  • Well, then I'm about to [blow your mind](https://developers.google.com/chrome-developer-tools/docs/videos#debugging)! – Alex Wayne Nov 14 '12 at 00:37