jquery - Internet Explorer、闭包编译器和尾随逗号

标签 jquery google-closure-compiler google-closure html5boilerplate build-script

我正在使用 html5boilerplate 构建脚本,并在缩小脚本时(使用 Google Closure 编译器)

我收到此错误

-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 })

如何让这段代码通过强制编译器?

谢谢

最佳答案

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

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 编译器所说,带有此类尾随逗号的文字无法被某些浏览器解析。

关于jquery - Internet Explorer、闭包编译器和尾随逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11823162/

相关文章:

javascript - 如何解决输入范围 slider 的跨浏览器兼容性问题?

javascript - 如何在没有构造函数的情况下在 Closure Compiler externs 中拥有类型

google-closure - Google之外的Google Closure应用示例?

javascript - 加载本地 JSON 文件

javascript - Slickgrid 或 Flexigrid

javascript - 如何通过事件对象从 originalEvent 传递数据?

javascript - 带有 eval 的函数无法通过缩小

javascript - Google Closure 引入错误

java - 加速谷歌闭包编译器 jar

javascript - Google Closure Compiler - 基于 externs 的死代码移除