Promises
をCoffeescriptで結ぶ方法はありますか?例えば、次のJavaScriptコードを考慮し、then's
のCoffeescriptで約束を結ぶ
return $.getJSON('/api/post.json')
.then(function(response) {
// do something
})
.then(function(response) {
// do something
})
.then(null, function(err) {
// do something
});
各々は任意であり、最終的なthen
は、関数によって返される必要があります。 現在、私は、などのCoffeeScriptでこれを書いています
promise = $.getJSON('/api/post.json')
promise = promise.then (response) ->
// do something
promise = promise.then (response) ->
// do something
promise = promise.then null, (err) ->
// do something
return promise
はこれを行うには良い方法はありますか?ありがとう。
$.getJSON('/api/post.json')
.then((response) ->
# do something
).then((response) ->
# do something
).then null, (err) ->
# do something
注then()
引数を囲む括弧:
また、IcedCoffeeScriptを見ることもできます。少し違って動作しますが、かなりうまく動作します。 –