问题
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
回答1:
I don't think you can do that with console.log()
. Try with console.error()
if you're fine with red output.
回答2:
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.
来源:https://stackoverflow.com/questions/21030027/getting-chromes-console-log-to-display-the-line-that-called-a-function