Joy
Joy

Reputation: 7028

Method chaining with nested method

I am new to coffeescript. However I didn't find any suitable word to put the question.

I have a coffeescript like this :

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

However, is there any better way to do this method chaining than this ugly syntax ? I want to find the td:last-child from $(@el) only, without any brackets. How can I do that?

Upvotes: 1

Views: 137

Answers (1)

mu is too short
mu is too short

Reputation: 434665

Why not put the parentheses on the append to match the other function calls?

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

Upvotes: 1

Related Questions