简体   繁体   English

Chrome JS调试帮助......函数调用在哪里?

[英]Chrome JS debugging help… where was function called?

I'm using console.log(var_name); 我正在使用console.log(var_name); to debug JS code in chrome and am wondering, is there a way to output to the console the line at which the current function was called? 在chrome中调试JS代码并且我想知道,有没有办法向控制台输出调用当前函数的行?

You can get the stack trace with the following: 您可以使用以下内容获取堆栈跟踪:

(new Error).stack;

You could then use a regular expression to filter out the line number: http://jsfiddle.net/8wA74/ . 然后,您可以使用正则表达式过滤出行号: http : //jsfiddle.net/8wA74/

var stack = (new Error).stack.split("\n"),
    line = /:(\d+):/.exec(stack[1]); // 1 is stack depth, format is "url:line:char"

console.log("Current function was called on line " + line[1]);
// this 1 is the number of the group in regexp

Not that i know of, but wouldnt it be possible to set a breakpoint instead? 不是我所知道的,但是设置断点是不可能的吗? That surely has a stacktrace visible. 这肯定有一个堆栈跟踪可见。

Just try to click the linenumber in the dev. 试着点击开发中的亚麻布。 console, it'll show a blue arrow and next time it hits it'll show you the stacktrace. 控制台,它会显示一个蓝色箭头,下次它会点击它会显示堆栈跟踪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM