Method chaining with function arguments

前端 未结 4 1578
囚心锁ツ
囚心锁ツ 2021-01-30 12:40

What\'s the best way to chain methods in CoffeeScript? For example, if I have this JavaScript how could I write it in CoffeeScript?

var req = $.get(\'foo.htm\')
         


        
4条回答
  •  天命终不由人
    2021-01-30 13:15

    I sometimes prefer having fewer parentheses as opposed to chaining, so I'd modify Trevor's last example:

    req = $.get 'foo.htm'
    req.success (response) -> # do something
    req.error -> # do something
    

提交回复
热议问题