9

我们很多人都知道,IE7 对包含尾随逗号的 JavaScript 代码不太友好,这对于使用现代 JS 框架和包含大量 JS 代码的项目来说可能是一个大问题。在关于这个主题的一篇相当不错的文章中,作者提到:

在工具方面,我更喜欢与这些恶魔作斗争的是 Eclipse JavaScript 开发工具。JSDT 中的 JavaScript 源代码编辑器将尾随逗号标记为错误:http ://www.enterprisedojo.com/wp-content/uploads/2010/12/jsdtRules.png

但是,将 Eclipse Indigo 与 WTP/JSDT 一起使用,我没有将尾随逗号视为错误,并且我找不到合适的设置来解决此问题。

如何设置 Eclipse 以将 JavaScript 中的尾随逗号标记为错误?

4

3 回答 3

3

看起来对另一个涉及逗号运算符错误语法错误的错误的修复也删除了初始化程序中尾随逗号的语法错误。这在技术上是正确的;标准说它们是允许的,而 IE7 只是不符合标准。有一个功能请求打开,要求恢复它们。

于 2012-01-25T22:33:56.323 回答
2

稍微偏离主题,但您还应该考虑使用 JSLint 来检查 JavaScript 代码的语法。它会警告您尾随逗号,以及许多其他潜在问题。Eclipse 有一个很好的插件,http ://marketplace.eclipse.org/content/phonegap-android-jslintjshint 。设置说明:http ://www.mobiledevelopersolutions.com/home/announce-1/mds12released-nowwithjslintjshint

于 2011-10-13T09:38:42.190 回答
0

Make sure you're in the correct perspective (ie JavaScript as opposed to Java).

Also, I found in Helios that if I added a JS file to the project by right-clicking and adding a new 'File' (which I would then name with a .js extension) didn't make the UI pick up that it should be treated as a JS file--no syntax highlighting, checking, etc. If I added it specifically using the new JavaScript file option, it worked fine.

于 2011-09-14T16:45:20.967 回答