Javascript JS 后缀操作中的左侧表达式无效?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11174170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JS Invalid left-hand side expression in postfix operation?
提问by Jeffrey Hunter
I am playing with a javascript and am running into an error. The error is this:
我正在使用 javascript 并遇到错误。错误是这样的:
Invalid left-hand side expression in postfix operation.
后缀运算中的左侧表达式无效。
And the script is long but I think this is this issue. The weird thing is this works when I run it locally, but when it is packaged, using asset_packager, it fails.
剧本很长,但我认为这就是这个问题。奇怪的是,当我在本地运行它时,这有效,但是当它使用 asset_packager 打包时,它失败了。
Any ideas why I might be getting this error?
任何想法为什么我可能会收到此错误?
UPDATE:After doing more research I found this function. The error seems to happen after in the "while" statement and I assume it's the "++ + a + ". This is a plugin so I didn't want to go messing with the code...but do you thing this could be it?
更新:经过更多研究,我发现了这个功能。该错误似乎发生在“while”语句之后,我认为它是“++ + a +”。这是一个插件,所以我不想弄乱代码......但是你认为这可能是它吗?
m.getInternetExplorerMajorVersion = function() {
var a = m.getInternetExplorerMajorVersion.cached = typeof m.getInternetExplorerMajorVersion.cached != "undefined" ? m.getInternetExplorerMajorVersion.cached : function() {
var a = 3, b = d.createElement("div"), c = b.getElementsByTagName("i");
while ((b.innerHTML = "<!--[if gt IE "++ + a + "]><i></i><![endif]-->") && c[0])
Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
;
return a > 4 ? a : !1
}();
return a
}
回答by chmurson
You didn't say which plugin was that but I was dealing with the same problem, Jeffrey, with I think the same plugin, because my code was looking almost the same.
你没有说是哪个插件,但我正在处理同样的问题,杰弗里,我认为是同一个插件,因为我的代码看起来几乎一样。
I followed your lead. The plugin was History.js, from page: https://github.com/browserstate/History.js/and I was using bundled html4+html5 version, which was minimized, and yet was going through my internal gzip compression.
我跟着你的脚步。该插件是 History.js,来自页面:https: //github.com/browserstate/History.js/,我使用的是捆绑的 html4+html5 版本,该版本已最小化,但正在通过我的内部 gzip 压缩。
I changed that fragment
我改变了那个片段
innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->"
into
进入
innerHTML="<!--[if gt IE "+ (++a)+"]><i></i><![endif]-->"
And it did the job!
它完成了工作!
I started to wonder what exactly problem lied in. The most important suspect was of course gzip. In normal situation following code is correct
我开始怀疑到底是什么问题。最重要的怀疑当然是gzip。在正常情况下,以下代码是正确的
var a=0; "begining of string "+ ++a+" the rest of string";
And returns "begining of string 1 the rest of string"
并返回 "begining of string 1 the rest of string"
However the gzip compression gets rid of white space and turns it into something that is understood by a browser as a:
然而,gzip 压缩消除了空白并将其转换为浏览器可以理解的内容:
var a=0;"begining of string "+++a+" the rest of string";
What gives us error Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
是什么给了我们错误 Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
As I thought - it that was gzip problem. It removed one white character too much.
Was using method gzencode($content, 9, FORCE_GZIP)
on PHP Version 5.4.8-1
正如我所想 - 那是 gzip 问题。它删除了太多的白色字符。gzencode($content, 9, FORCE_GZIP)
在 PHP 版本 5.4.8-1 上使用方法
回答by matt3141
This error is in reference to a ++
or --
following a non reference, such as a returned value. The problem is somewhere else in your code.
此错误是引用++
或--
跟随非引用,例如返回值。问题出在您的代码中的其他地方。