Internet Explorer, Closure Compiler and Trailing Commas

匿名 (未验证) 提交于 2019-12-03 00:56:02

问题:

I'm using html5boilerplate build script and when minifying the scripts (which uses Google Closure Compiler)

I'm getting this error

-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]                ^

But the code DOES work in IE 8 if run uncompiled.

This is the code

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

How can I make this code pass Compulsure Compiler?

Thanks

回答1:

Remove the superfluous last comma from your object literal:

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

As the Closure compiler says, literals with such trailing commas cannot be parsed by some browsers.



回答2:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!