且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是什么原因导致我在Firefox开发人员控制台中看到语法错误?

更新时间:2023-01-06 15:51:40

由于指示的脚本行不包含任何视觉语法错误,因此问题可能是该行中的一个不可见的非法字符,例如零宽度空间.在这种情况下,只需重写您的函数并确保替换所有文件,直到文件的开头即可.

As the indicated script line doesn't contain any visual syntactical error, the problem is probably either an invisible illegal character within that line like e.g. a zero-width space. In that case just rewrite your function and ensure you replace everything up to the beginning of the file.

或者行号在控制台内显示不正确,并且错误实际上在其他地方.要进行测试,只需从脚本中删除该函数,然后查看第一行是否仍然显示语法错误.如果是这样,您可以删除脚本的其他部分,并在错误消失时逐步检查.

Or the line number is incorrectly displayed within the console and the error is actually somewhere else. To test that simply remove that function from the script and see whether there is still a syntax error displayed at line one afterwards. If so, you may remove other parts of your script and step by step check when the error disappears.

检查它是否是Firefox中的错误的另一种方法是通过另一个浏览器确认该错误,即查看是否在其他DevTools控制台的同一行中也显示了该错误.如果不是,则应该创建新的Firefox配置文件,以测试错误消息是否实际上来自您的代码.如果新的配置文件没有显示错误,则很可能是由某些加载项或插件引起的错误.

Another way to check whether it's a bug within Firefox is to confirm that error with another browser, i.e. see if it is also displayed at the same line in the console of other DevTools. If it isn't, you should create a new Firefox profile to try out whether the error message actually comes from within your code. If the new profile doesn't display the error, chances are high that the error is caused by some add-on or plugin.

有关此的一些注意事项:

Firebug大部分时间还提供有关发生语法错误的列的信息,并指出确切的位置:

Firebug most of the time also provides information about the column where the syntax error occurred and indicates the exact place: