【问题标题】:Method chaining with nested method嵌套方法的方法链
【发布时间】:2012-09-12 11:08:24
【问题描述】:

我是咖啡脚本的新手。但是我没有找到任何合适的词来提出这个问题。

我有一个这样的咖啡脚本:

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

但是,有没有比这种丑陋的语法更好的方法链接?我只想从 $(@el) 中找到 td:last-child,不带任何括号。我该怎么做?

【问题讨论】:

    标签: coffeescript


    【解决方案1】:

    为什么不在append 上加上括号以匹配其他函数调用?

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

    【讨论】:

    • 所以在某种程度上我仍然需要用括号来区分项目和查找链接吗?
    • @Joy:如果你想链接,你将需要括号。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    相关资源
    最近更新 更多