1

Is there any way in the Chrome Console tab to display the address that called a function?

I have a function that's being called but I don't know where from. I know I could break and look at the Call Stack but I'd rather just display at each entry who called it:

functon select_el() {
console.log("select_el called by " + ?????);

    etc.
}

Thanks

Steve
  • 4,534
  • 9
  • 52
  • 110
  • Are you looking for the line number or a stack trace? – BanksySan Jan 09 '14 at 20:07
  • I just want the number of the line where the function was called. – Steve Jan 09 '14 at 20:18
  • possible duplicate of [How to get JavaScript caller function line number? How to get JavaScript caller source URL?](http://stackoverflow.com/questions/1340872/how-to-get-javascript-caller-function-line-number-how-to-get-javascript-caller) – BanksySan Jan 09 '14 at 20:30

2 Answers2

3

I don't think you can do that with console.log(). Try with console.error() if you're fine with red output.

Daniel Lidström
  • 9,930
  • 1
  • 27
  • 35
0

The answer to this question might be what you are looking for.

It uses the trick of throwing an exception, then accessing the LineNumber property and printing it.

Community
  • 1
  • 1
BanksySan
  • 27,362
  • 33
  • 117
  • 216