Using then() Versus done()

In the previous section, we used the Promise object done() method to set up our complete, error, and progress callbacks. The Promise object exposes another method that is closely related to done(): the then() method.

The then() method—just like the done() method—enables you to set up a complete, error, and progress callback function. So why does the then() method exist? There are two important differences between then() and done().

The then() method, unlike the done() method, supports chaining. If you need to chain multiple promises together then you are forced to use the then() method. For example, the code in Listing 2.8 illustrates how you can make one Ajax call that downloads the URL of the most recent blog entry ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.