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

  • MofoHifi Records

    MofoHifi Rec

    15 HAZİRAN 2006
  • Rhapsody

    Rhapsody

    7 ŞUBAT 2008
  • Sergio Lafuente Rubio

    Sergio Lafue

    11 Aralık 2008