23

Possible Duplicate:
What are the differences between Deferred, Promise and Future in Javascript?

Can someone point out what are the differences are between callbacks and promises? When should one use promise etc?

Also links on how to create and use promises will be appreciated.

Community
  • 1
  • 1
NSS
  • 1,835
  • 2
  • 29
  • 66

1 Answers1

44

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()
        })
    })
});
Ben McCormick
  • 25,260
  • 12
  • 52
  • 71