2

我正在使用 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(),它工作正常。这是为什么?

4

1 回答 1

2

问题是隐藏在我的代码中某处的坏字符,因为我从一些片段中复制粘贴。它是看不见的,所以很难被发现。

于 2013-08-07T20:40:14.673 回答