如何获取JSfiddle中的行错误数

时间:2016-09-18 17:12:07

标签: javascript google-chrome jsfiddle

使用下面的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

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

返回行号。您需要展开<{1}}

删除评论后

ReferenceError: x is not defined(…)

错误将在第3行。扩展try { console.log("hello world"); console.log(x); //x was never defined } catch (error) { console.log(error); } 揭示

铬,铬at <anonymous>:3:15