• Click a launch button...

Escaping Callback Hell!

Because a lot of the things we do with Javascript tend to happen asynchronously, it's easy to get caught up in callback hell. Not only does this look ugly but it makes our code hard to reason about as the logical flow becomes obscured. Futures to the rescue!

Futures, Deferreds, and Promises are all (more-or-less) different names for the same idea. jQuery has included a deferred implementation since 1.5 - the code samples below do the same thing but demononstrate some of the advantages of using Promises to control flow where previously you may have used callbacks.

Futures aren't just to manage really complicated code - fairly straightforward things you may typically want to do as a jQuery developer (grab two lists of tweets, add a new tweet on the page every few seconds) might also benefit from a sprinkling of deferreds!

Read the blog post to learn more »

Callback Style

Show me the code! Run


Show me the code! Run