JavaScript有assignment operators對應arithmetic的:+=
,-=
,*=
,/=
,%=
。簡單的JavaScript代碼中賦值運算符的替代?
的JavaScript也有assignment operators對應bitwise的:<<=
,>>=
,>>>=
,&=
,^=
,|=
。
但它沒有assignment operators對應於logical個:||=
,&&=
。
然後,我不能做這樣的事情
aVeryLongVariableIdontWantToRepeat ||= 1;
在this other question它解釋了爲什麼 JS Java沒有這樣的運營商。我想JS也是一樣。
但我想知道是否有一個簡單的方法來模仿他們,避免
aVeryLongVariableIdontWantToRepeat = aVeryLongVariableIdontWantToRepeat || 1;
簡單縮短變量名稱怎麼樣? –
您鏈接到的其他問題不是關於JavaScript,而是關於Java。 –
@ T.J.Crowder Oh,true – Oriol