问题
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