क्या कॉफ़ीस्क्रिप्ट में Promises
चेन करने का कोई तरीका है। उदाहरण के लिए, निम्नलिखित जावास्क्रिप्ट कोड पर विचारकॉफ़ीस्क्रिप्ट में चेनिंग वादे
return $.getJSON('/api/post.json')
.then(function(response) {
// do something
})
.then(function(response) {
// do something
})
.then(null, function(err) {
// do something
});
then's
से प्रत्येक वैकल्पिक है, और अंतिम 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 पर भी एक नज़र डाल सकते हैं। यह थोड़ा अलग काम करता है, लेकिन यह काफी अच्छी तरह से काम करता है। –