2009-07-15 60 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); 

雖然我不能說我見過像這樣的線在生產代碼:)