2012-09-20 55 views
1

我是新來的coffeescript。但我沒有找到任何合適的詞來提出這個問題。用嵌套方法鏈接的方法

我有這樣一個CoffeeScript的:

@collection.each (student) =>    
      ($(@el).find("#table .table").append new Item({model:student}).el) 
       .find("td:last-child").hide() 

如何過有沒有更好的辦法做的比這個醜陋的語法,這種方法鏈接?我只想從$(@ el)找到td:last-child。沒有任何括號?怎麼做 ?有人可以從上面提到的更好的語法嗎?

回答

1

爲什麼不把append的圓括號與其他函數調用相匹配?

@collection.each (student) =>  
    $(@el).find("#table .table") 
     .append(new Item(model: student).el) 
     .find("td:last-child") 
     .hide() 
+0

所以我仍然必須把括號區分項目和發現鏈接權利? – Joy

+1

@Joy:如果你想鏈接,你會在某個地方需要圓括號。 –