javascript - JSC_TRAILING_COMMA : Parse error. IE8(及更低版本)- jshint 可以警告我左尾随逗号吗?

标签 javascript internet-explorer-8 google-closure-compiler jshint google-closure

使用Google Closure Compiler我收到此错误:

JSC_TRAILING_COMMA: Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option. at line 7 character 9
        },

对于以下代码:

App.prototype = {
    testA: function () {

    },
    testB: function () {

    },
};

我想知道是否 jshint有一些内置选项可以检测尾随逗号并显示警告消息。

最佳答案

JSHint 会警告您 "Extra comma. (it breaks older versions of IE)"如果您设置 es3 选项(在版本 2.0.0 及更高版本中):

/*jshint es3: true */
var x = {
    prop1: 10,
    prop2: 20,
};

在旧版本的 JSHint 中,您不需要设置 es3 选项,因为它是默认选项。所有版本的 JSLint 也会给出类似的警告。

关于javascript - JSC_TRAILING_COMMA : Parse error. IE8(及更低版本)- jshint 可以警告我左尾随逗号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29119285/

相关文章:

css - Internet Explorer 8 显示渐变而不是背景图像

javascript - 防止 IE8 的默认操作

javascript - SAPUI5 表排序不起作用

javascript - 引用函数数组中的另一个函数

javascript - 如何检测浏览器是否支持聚焦于禁用元素?

javascript - 如何在浏览器中使用 Google 编译器而不请求服务?

javascript - 在 JavaScript 中混淆字符串文字和对象键?

javascript - 如何实现滚动条

javascript - 向服务器传递参数(Stripe Connect 中的 oAuth 回调)

google-closure-compiler - 警告白名单在 Google 闭包编译器中不起作用