Javascript Closure Compiler Error Trailing Comma?

时间:2014-04-06 14:29:17

标签: javascript minify google-closure-compiler

当谷歌通过名为Closure Compiler的便捷工具中缩小JavaScript时,它会出现以下错误(并且不会缩小某个内容):

  

错误数:1 JSC_TRAILING_COMMA:解析错误。 IE8(及以下)   将错误地解析数组和对象文字中的尾随逗号。   如果您要定位较新版本的JS,请设置相应的版本   language_in选项。在all.js的第389行第1号

theme : 'default', // The theme of the slider (default, theme1, theme2, t...

故障在哪里以及需要更改什么来修复错误?

$(window).load(function(){
jQuery('#slider1').autoSlider({
    theme               : 'default',    // The theme of the slider (default, theme1, theme2, theme3)
    width               : '960',    // The width of the slider, 100% for auto full width, set to 0 it will take the width of the largest image
    autoHidePlayBtn     : true,     //

2 个答案:

答案 0 :(得分:8)

错误(因为害怕简单地重写Closure Compiler错误所说的内容)是IE8及以下版本无法解析具有尾随逗号的对象文字和数组文字。

var obj = {
    a: 1,
    b: 2, // trailing comma is bad!
};

...... vs ...

var obj = {
    a: 1,
    b: 2 // no trailing comma!
};

修复方法是删除尾随的逗号。

答案 1 :(得分:2)

您有三种方法可以摆脱此警告:

  1. 删除尾随逗号
  2. 将编译模式(使用language_in)更改为以后的编译模式,例如ECMASCRTIPT6或ECMASCRIPT6_STRICT(尾随逗号在EcmaScript 5中标准化)。
  3. 将“es3”诊断组的编译器警告级别更改为“OFF”。