2009-07-15 61 views
3

有人能解释为什么javascriptlint(不JSLint的)给出了警告JavaScript的林特inc_dec_within_stmt警告

inc_dec_within_stmt - increment (++) and decrement (--) operators used as part of greater statement 

的原因/重要性,当它遇到的代码行像

someValue = count++; 

我为什么要保持这个检查打开?

回答

5

这是一个警告,因为这样的陈述对于读者来说可能是模棱两可的。

虽然你和我可以看看那个和理解,它相当于

someValue = count; 
count = count + 1; 

一个缺乏经验的程序员可能会错误地解释,由于

someValue = count + 1; 

当然,这是最简单的例子。该警告是更在一条线上当之无愧像

someValue = (count++) * (--index)/(3 * ++j); 

虽然我不能说我见过像这样的线在生产代码:)