Chapter 13. Avoiding the callback hell with Deferred

This chapter covers

  • What promises are and why they’re important
  • The Deferred object
  • How to manage multiple asynchronous operations
  • Resolving and rejecting a promise

For a long time, JavaScript developers have used callback functions to perform several tasks such as running operations after a given amount of time (using set-Timeout()), or at regular intervals (using setInterval()), or to react to a given event (click, keypress, load, and so on). We’ve discussed and employed callbacks extensively to perform asynchronous operations; for example, in chapter 6 where we focused on events, in chapter 8 when we talked about animations, and in chapter 10 where we covered Ajax. Callback functions ...

Get jQuery in Action, Third Edition 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.