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

Chrome JS debugging help... where was function called?

本文关键字:在哪里 调用 函数 帮助 JS 调试 Chrome      更新时间:2023-09-26

我使用console.log(var_name);在chrome中调试JS代码,我想知道,是否有一种方法可以输出到控制台当前函数被调用的行?

您可以使用以下命令获取堆栈跟踪:

(new Error).stack;

然后可以使用正则表达式过滤出行号: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

我不知道,但不可能设置一个断点代替?这肯定有一个可见的堆栈跟踪。

试着点击dev. console中的linenumber,它会显示一个蓝色箭头,下一次点击时,它会显示stacktrace