gpt4 book ai didi

javascript - 如何获取 JSfiddle 中错误的行号

转载 作者:行者123 更新时间:2023-12-03 06:05:42 27 4
gpt4 key购买 nike

使用下面的 JavaScript,我可以使用 JSfiddle 编辑器在 Safari 中记录行号错误,但不能使用 Chrome 或 Firefox。我意识到我可以使用 Firebug 插件在 Firefox 中获取行号错误,但是我想在 Chrome 中使用 JSfiddle 和 Firebug Lite 作为外部资源来执行相同的操作

//I pasted all of this into the JAVASCRIPT portion of jsfiddle editor
//I then pasted the FireBug Lite URL in the External Resources (left menu in jsfiddle) :
//https://getfirebug.com/firebug-lite-debug.js
//then hit enter
try {
console.log('hello world');
//console.log(x); //x was never defined
console.log(x); //x was never defined
} catch (error) {
console.log(error);
//is there a way to include line 8 with the RererenceError?
//I tried Safari and get this output: ReferenceError: Can't find variable: x {line=55, ...}
var errorLineNumber = Number(error.line) - 48;
console.log('Line number of the error is: ' + errorLineNumber) //works in safari to log: Line number of the error is: 8
//In Chrome and Firefox, it logs: Line number of the error is: NaN
} //then clicked Run in JSfiddle

感谢任何帮助。

最佳答案

返回行号。您需要展开... at

ReferenceError: x is not defined(…)

删除评论后

try {
console.log("hello world");
console.log(x); //x was never defined
} catch (error) {
console.log(error);
}

错误出现在第 3 行。展开 ... 显示

at <anonymous>:3:15

在 chrome,在 控制台 上使用 chromium

关于javascript - 如何获取 JSfiddle 中错误的行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39560451/

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