Unexpected '++' in jslint [duplicate]

风格不统一 提交于 2019-12-01 00:01:32

问题


Possible Duplicate:
Why avoid increment (“++”) and decrement (“--”) operators in JavaScript?
The “unexpected ++” error in jslint

jslint.com is giving me the error:

Unexpected '++'.

for this line:

for (i = 0; i < l; ++i) {

I tried i++ but no go.


回答1:


JSLint does not like the increment and decrement operators. Replace it with i += 1 or add the plusplus: true directive to the top of your file (if you're not sure how to set JSLint directives, here's an example. They are set in a normal comment at the top of your file):

/*jslint plusplus: true */

From the JSLint docs:

The ++ (increment) and -- (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces.

Completely ridiculous rule? You can make your own mind up...




回答2:


Try: for (var i = 0; i < l; i++) {

If that doesn't work, see if i is defined by typing i in console and seeing the response.



来源:https://stackoverflow.com/questions/11996293/unexpected-in-jslint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!