【发布时间】:2013-07-28 06:28:59
【问题描述】:
我正在使用 r.js 来优化/丑化我使用 RequireJS 的 JavaScript 代码。
我的一个模块是一个 polyfill 模块:
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
将var isPolyfillNeeded = function () 替换为function isPolyfillNeeded() 时,它可以正常工作。
这是为什么呢?
【问题讨论】:
-
该函数的主体是什么样的?
-
@Blender 显然我有一个坏角色躲在某个地方(见stackoverflow.com/questions/12719859/…)。我仍然无法解释为什么 var-function 更改解决了它,但无论如何 - 删除一个坏字符修复它。谢谢。
标签: requirejs js-amd uglifyjs r.js