问题
Can someone explain the reason/importance of why javascriptlint (not jslint) gives the warning
inc_dec_within_stmt - increment (++) and decrement (--) operators used as part of greater statement
when it comes across a line of code like
someValue = count++;
Why should I keep this check turned on?
回答1:
It's a warning because a statement like that can be ambiguous to human readers.
While you and I can look at that and understand that it is equivalent to
someValue = count;
count = count + 1;
a less experienced programmer might incorrectly interpret that as
someValue = count + 1;
Of course, this is the simplest example. The warning is much more deserved in a line like
someValue = (count++) * (--index) / (3 * ++j);
although I can't say I've ever seen a line like that in production code :)
来源:https://stackoverflow.com/questions/1132001/javascript-lint-inc-dec-within-stmt-warning