I'm wondering if it's possible to get the line number of a statement inside a .js file. For instance:
// line 1
// line 2
detectLineNumber();
// line 4
How can I have detectLineNumber()
to find where it was invoked and console-log the line number 3
? Is it possible?
UPDATE
I'm afraid (new Error).lineNumber
won't work for me since it doesn't work in Chrome. Answer should be cross-browser.