对象不支持此操作 - 突然

时间:2015-06-14 01:48:30

标签: javascript less

我正在运行1.7.5版本,并且由于一些不可理解的原因,突然之间我遇到了语法错误(我的样式表都没有改变,因为它正在工作)而且我包括.js文件的方式相同):

  

对象不支持此操作

我已将错误追溯到这个奇怪的片段(第7880行):

new(less.Parser)(env).parse(data, function (e, root) {
    if (e) { return callback(e, null, null, sheet); }
    try {
        callback(e, root, data, sheet, webInfo, path);
    } catch (e) {
        callback(e, null, null, sheet);
    }
}, {modifyVars: modifyVars, globalVars: less.globalVars});

...在loadStyleSheet函数中。事实上,我并不理解这种语法,并且在控制台上尝试它会得到相同的错误消息:

new(less.Parser) # fails
new(less.Parser)(env) # fails
typeof less.Parser # yields "function"

这里发生了什么?

  

描述:"对象不支持此操作"       消息:"对象不支持此操作"       号码:-2146827843      stack:" TypeError:Object在Parser中不支持此操作   (http://localhost:53109/Scripts/System/less-1.7.5.js:360:5)\ n at   匿名功能   (http://localhost:53109/Scripts/System/less-1.7.5.js:7880:13)\ n at   匿名功能   (http://localhost:53109/Scripts/System/less-1.7.5.js:7838:13)\ n at   用handleResponse   (http://localhost:53109/Scripts/System/less-1.7.5.js:7763:13)\ n at   doXHR(http://localhost:53109/Scripts/System/less-1.7.5.js:7783:9)\ n
  在loadFile   (http://localhost:53109/Scripts/System/less-1.7.5.js:7832:5)\ n at   loadStyleSheet   (http://localhost:53109/Scripts/System/less-1.7.5.js:7856:5)\ n at   loadStyleSheets   (http://localhost:53109/Scripts/System/less-1.7.5.js:7896:9)\ n at   less.refresh   (http://localhost:53109/Scripts/System/less-1.7.5.js:7973:5)\ n at   匿名功能   (http://localhost:53109/Scripts/System/less-1.7.5.js:7999:1)"

*更新I *

所以语法似乎没问题。我能做到:

new(function() {})('x')

所以假设less.Parser是一个函数,代码应该可以工作......但它并没有。如果我看一下less.Parser

,我会得到什么
function Parser(env) {
    var input,       // LeSS input string
        i,           // current index in `input`
        j,           // current chunk
        saveStack = [],   // holds state for backtracking
        furthest,    // furthest index the par
    [Methods]: {...}
    __proto__: 
function() {
    [native code]
}

    arguments: null
    caller: null
    length: 1
    prototype: {...}

看起来有什么不妥吗?

*更新II *

实现1.7.5远远落后于当前,我升级到2.5.0(正好在CDN之后),但现在它在别处打破(第2440行):

if (typeof Object.create === 'undefined') {
    var F = function () {};
    F.prototype = Error.prototype;
    LessError.prototype = new F();
} else {
    LessError.prototype = Object.create(Error.prototype); # breaks here
}

错误:

  

Object.create:参数不是Object而不是null

如果我看Error.prototype,我会undefined ... grr ...

1 个答案:

答案 0 :(得分:1)

经过一番嚎叫和咬牙切齿之后,我发现了它。我的一个脚本是设置:

var Error = {};

吸取的教训:注意你的变量名!如果编译器抱怨它会很好。

相关问题