Domanda

Why is jslint complainig about this syntax:

var myint;
myint = 0;

myint++;

www.jslint.com response:

Unexpected '++'. myint++;

È stato utile?

Soluzione

JSLint doesn't like ++, it wants you to use myint += 1. This is highly debatable, see Why avoid increment ("++") and decrement ("--") operators in JavaScript?

There is an option to let it pass, though (on the web interface, it's under "tolerate...").

From JSLint help:

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. Also, preincrement/postincrement confusion can produce off-by-one errors that are extremely difficult to diagnose. There is a plusplus option that allows the use of these operators.

Altri suggerimenti

Crockford's argument against ++ and -- is that they are "too tight, too tricky, too cryptic" (page 112 of Javascript: the good parts). Your mileage may vary. Use them if you want, or if you think they are too confusing and hamper readability, don't.

You can switch that rule off in JSLint if you don't buy Crockford's argument.

@bfavaretto's answer is correct. If you want to allow this (assuming you're using a non-web version), set plusplus to true with this directive:

/*jslint plusplus: true */

Reference

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top