<story><title>Escape from Callback Hell</title><url>http://ianbishop.github.com/blog/2013/01/13/escape-from-callback-hell/</url></story><parent_chain></parent_chain><comment><author>Swizec</author><text>I honestly find &quot;callback hell&quot; a lot easier to follow and understand than the vast majority of fixes everyone is coming up with.&lt;p&gt;They&apos;re just continuations, seriously, what&apos;s everyone&apos;s problem? You define a function, it gets access to the current scope, it defines the rest of the program flow.&lt;p&gt;If you feel like your code is nesting too deep, you define the function elsewhere and just reference it by name. Then you don&apos;t get access to the current scope.&lt;p&gt;Why is this so difficult to people?</text></comment>
<story><title>Escape from Callback Hell</title><url>http://ianbishop.github.com/blog/2013/01/13/escape-from-callback-hell/</url></story><parent_chain></parent_chain><comment><author>etrinh</author><text>Good overview of jQuery Deferred and how to use promises (at least the jQuery flavor). Promises (or futures) are a simple concept: an object-level abstraction of a non-blocking call, but they&apos;re very powerful when you see them in action. For example, the $.when method:&lt;p&gt;Let&apos;s say you have 3 ajax calls going in parallel. With $.when, you can attach callbacks to arbitrary groupings of those ajax calls (callback1 runs when ajax1 and ajax2 are done, but callback2 runs when ajax1 and ajax3 are done).&lt;p&gt;I first learned about promises in Trevor Burnham&apos;s excellent book Async Javascript (&lt;a href=&quot;http://pragprog.com/book/tbajs/async-javascript&quot; rel=&quot;nofollow&quot;&gt;http://pragprog.com/book/tbajs/async-javascript&lt;/a&gt;) and it is still the best explanation of promises I&apos;ve ever read. If you like this article and are interested in reading further about promises or the asynchronous nature of Javascript in general (both for browser and node.js), I highly recommend you check out this book.</text></comment>