0

Let's say I have this code:

promise.done(function (x) {
    // First done()
    console.log(x);
    return 123;
}).fail(function (x){
    // First fail()
    console.log(x);
}).then(function (x){
    // First then()
    console.log(x)
}).fail(function (x){
    // Second fail()
    console.log(x);
}).done(function (x){
    // Second then()
    console.log(x);
});

How will this execute? If nothing goes wrong, will the chain of execution be:

1. The first done()
2. The first then()
3. The second done()

If something goes wrong in the first done, will both the first and second fail() be called?

Sorry for the new question, I'm trying to learn how chaining works with promises. Thanks!

joshualan
  • 2,030
  • 8
  • 23
  • 32
  • 2
    Do execute this and check.. What have you tried which does not work as you expect ? – Rayon May 04 '16 at 12:12
  • 2
    Don't use `done` or `fail`. Just always use `then`. – Bergi May 04 '16 at 13:07
  • jQuery [ignores exceptions in handlers](http://stackoverflow.com/q/23744612/1048572), it doesn't catch them like a proper promise library would. – Bergi May 04 '16 at 13:09
  • @Bergi If you use then, how would you handle failures? – joshualan May 06 '16 at 11:24
  • [`then`](http://api.jquery.com/deferred.then/) has a second parameter that you should use: `.then(null, function onReject(err) { … })` – Bergi May 06 '16 at 12:02

0 Answers0