8 Temmuz 2011, Cuma
Nasıl düzgün Coffeescript ifadeleri eğer uzun bileşik önerilir
Eğer bir karmaşık if ben gördüm taşma sadece estetik amaçlı, ne olurdu en helal şekilde kesin artık beri coffeescript yorumlayacaktır verir gibi vücudun deyimi bu durumda?
if (foo is bar.data.stuff and foo isnt bar.data.otherstuff) or (not foo and not bar)
awesome sauce
else lame sauce
CEVAP
8 Temmuz 2011, Cuma
CoffeeScript eğer hattı operatörü ile bitiyorsa deyiminin vücut olarak bir sonraki satıra yorumlamak değil, bu tamam.
# OK!
if a and
not
b
c()
için derler
if (a && !b) {
c();
}
bu yüzden
# OK!
if (foo is
bar.data.stuff and
foo isnt bar.data.otherstuff) or
(not foo and not bar)
awesome sauce
else lame sauce
ya da başka bir kırma hat düzeni çok uzun satırları and
or
is
==
not
ya da onun gibi bir operatör son olarak
Girinti olarak, if
vücudun daha girintili olduğu sürece: non-ilk satır girinti
# OK!
if (foo is
bar.data.stuff and
foo isnt bar.data.otherstuff) or
(not foo and not bar)
awesome sauce
else lame sauce
Yapamayacağın şey:
# BAD
if (foo #doesn't end on operator!
is bar.data.stuff and
foo isnt bar.data.otherstuff) or
(not foo and not bar)
awesome sauce
else lame sauce
Bunu Paylaş:
Eğer kullanıcı giriş olup olmadığını k...
Eğer bir kayıt varsa düzgün bir şekild...
Nasıl düzgün bir bileşik birincil anah...
Nasıl eğer bir dizin zaten mevcut deği...
Nasıl düzgün Excel, birlikte çalışabil...