我正在运行版本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堆栈:“ TypeError:对象不支持此操作,在解析器中(http:// localhost:53109 /Scripts/System/less-1.7.5.js:360:5)\ n在匿名函数(http:// localhost:53109 / Scripts / System / less-1.7.5.js:7880:13)\ n在handleResponse的匿名函数(http:// localhost:53109 / Scripts / System / less-1.7.5.js:7838:13)\ n(http:// localhost:53109 / Scripts / System / less-1.7.5。 js:7763:13)\ n在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在loadStyleSheet(http:// localhost:53109 / Scripts / System / less-1.7.5.js:7856:5)\ n在loadStyleSheets(http:// localhost:53109 / Scripts / System / less-1.7.5.js:7896 :9)\ n在less.refresh(http:// localhost:53109 / Scripts / System / less-1.7.5.js:7973:5)\ n在匿名函数(http:// localhost:53109 / Scripts / System / less-1.7.5.js:7999:1)“
*更新我*
因此语法似乎没问题。我可以:
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 ...
经过一阵哭泣和咬牙切齿,我弄清楚了。我的脚本之一是设置:
var Error = {};
经验教训:当心您的变量名!如果编译器抱怨过,那就太好了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句