SORU
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ş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Ben Vivona

    Ben Vivona

    24 Ocak 2010
  • michellefeng's channel

    michellefeng

    26 Kasım 2006
  • MyCyberAcademy

    MyCyberAcade

    2 EKİM 2011