我刚刚在一个第三方wordpress插件中发现了一个bug,它看起来是由javascript代码压缩器引起的。
我认为,最初的代码应该是:
this.id = "ui-id-" + ++n;
相反,它被缩小为:
this.id="ui-id-"+++n;
这会导致Chrome中出现以下错误:
Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
在Firefox中也有类似的错误。令人烦恼的是,在Chrome中,我自己的插件Javascript函数仍然被成功创建,但是在Firefox中,这个错误导致我的函数没有被创建,插件也失败了。
var n = 1;
var foo = 10;
var bar = "ID-";
console.log(foo+++n); // results in 11
console.log(foo); // also results in 11
console.log(bar+++n); // results in NaN soft error/warning
console.log ("ID-"+ ++n); // results in ID-2
console.log ("ID-"+++n); // hard error
我不知道该问什么问题-
发布于 2013-07-11 10:41:03
我看到了问题4.唯一有趣的问题,所以我只回答(1.是琐碎的:“这是语言的定义”,2.我不知道,3.我不明白):
答案在于你引用的错误:
不正确的引用错误:在后缀操作中无效的左侧表达式
++
是修改操作,它需要“左手边的表达”。bar
是可变的,所以它是LHS,"ID-"
是文字,所以它不是LHS。
https://stackoverflow.com/questions/17591136
复制相似问题