What is the difference between callback and promise
This question already has an answer here:
Promises provide a more succinct and clear way of representing sequential asynchronous operations in javascript. They are effectively a different syntax for achieving the same effect as callbacks. The advantage is increased readability. Something like this
aAsync()
.then(bAsync)
.then(cAsync)
.done(finish);
is much more readable then the equivalent of passing each of those individual functions as callbacks, like
Async(function(){
return bAsync(function(){
return cAsync(function(){
finish()
})
})
});
链接地址: http://www.djcxy.com/p/55438.html
上一篇: 如何使用promise来避免回调地狱?
下一篇: 回调和承诺有什么区别