gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:26:17 25 4
gpt4 key购买 nike

我正在使用 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

关于javascript - Chrome JS 调试帮助...函数在哪里调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8328579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com