Chaining Promises in Coffeescript

前端 未结 3 1950
慢半拍i
慢半拍i 2021-02-02 08:56

Is there a way to chain Promises together in Coffeescript. For example, consider the following javascript code,

return $.getJSON(\'/api/post.json\')         


        
3条回答
  •  攒了一身酷
    2021-02-02 09:05

    This is probably the best you'll do:

    $.getJSON('/api/post.json')
        .then( (response) ->
          # do something
        ).then( (response) ->
          # do something
        ).then null, (err) ->
          # do something
    

    Note the parentheses surrounding the then() arguments. Nothing earth shattering but hopefully this helps.

提交回复
热议问题