5

我正在使用 html5boilerplate 构建脚本并在缩小脚本时(使用 Google Closure Compiler)

我收到此错误

-js.all.minify:
     [echo] Minifying scripts
     [copy] Copying 3 files to /Users/Username/Desktop/Web/intermediate/js
    [apply] /Users/Juan/Desktop/Web/js/plugins.js:117: ERROR - Parse error. Internet Explorer has a non-standard intepretation of trailing commas. Arrays will have the wrong length and objects will not parse at all.
    [apply]                 }, { duration: 727 })
    [apply] 

             ^

但是如果运行未编译,代码确实可以在 IE 8 中运行。

这是代码

anim1.animate({
                    'left': '+=32px',
                    'filter': 'alpha(opacity=100)',
                    '-moz-opacity': '1',
                    '-khtml-opacity': '1',
                    'opacity': '1',
                }, { duration: 727 })

如何使此代码通过 Compulsure 编译器?

谢谢

4

2 回答 2

10

从对象文字中删除多余的最后一个逗号:

anim1.animate({
    'left': '+=32px',
    'filter': 'alpha(opacity=100)',
    '-moz-opacity': '1',
    '-khtml-opacity': '1',
    'opacity': '1'      // <-- No comma here.
}, { duration: 727 });  // <-- I'd also suggest a semicolon there.

正如 Closure 编译器所说,某些浏览器无法解析带有这种尾随逗号的文字。

于 2012-08-06T06:03:49.550 回答
4

Or enable EcmaScript 5 mode. Ecmascript 5 does standardize the trailing comma behavior but IE8 does not fully support it ES5 (neither does IE9 which is missing strict mode).

于 2012-08-06T18:01:37.693 回答