Getting Chrome's console.log to display the line that called a function

人走茶凉 提交于 2019-12-18 09:45:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!