2
我正在使用r.js來優化/ uglify我使用RequireJS的JavaScript代碼。uglify與r.js拋出解析錯誤
我的一個模塊是一個填充工具模塊:
define(function(){
if (!Array.prototype.filter)
{ /* ... */ }
var isPolyfillNeeded = function() { /* ... */ }
if (isPolyfillNeeded()) {
/* polyfill implementation */
}
});
模塊會試圖醜化它的時候,他說從r.js拋出分析錯誤:
Tracing dependencies for: ../scripts/main-app
Error: Parse error using UglifyJS for file: C:/.../polyfill.js
Unexpected character '?' (line: .., col: .., pos: ..)
undefined
In module tree:
../scripts/main-main-app
moduleA
moduleB
當function isPolyfillNeeded()
更換var isPolyfillNeeded = function()
,它工作正常。 這是爲什麼?
該函數的主體是什麼樣的? – Blender
@Blender顯然我有一個隱藏在某處的壞字符(請參閱http://stackoverflow.com/questions/12719859/syntaxerror-unexpected-token-illegal)。我仍然無法解釋爲什麼var函數的變化解決了它,但無論如何 - 刪除壞字符修復了它。謝謝。 – Haji