coffeescriptjquery-deferrediced-coffeescript

IcedCoffeeScript or jQuery deferred


Recently while working on a Backbone.JS/jQuery/CoffeeScript project, I found myself in a mess of callback and timing issues. I needed to wait for something to complete before proceeding and found myself in a mess of nested callbacks ... which is confusing and hard to debug. Then I found 2 possible solutions jQuery deferred or IcedCoffeeScript

IcedCoffeeScript looks really easy, simply adding await & defer. However, I wonder if its there to stay? Only 2 questions here on StackOverflow? Not much talk about it compared to CoffeeScript

Another thing is whats the difference between the 2 methods, they seem to do mostly the same thing? Except in IcedCoffeeScript, it looks more like procedural code, and in jQuery deferred, it doesn't solve my mess of callbacks as much


Solution

  • These are very different technologies:

    Each of these technologies works best with a certain kind of API. await and defer expect a function to take a single callback as its last argument. Promises work best when you have lots of other Promises in your app.

    There's no magic bullet for dealing with async behavior in JavaScript. You need to understand callbacks, Promises, and PubSub (aka EventEmitters) and choose the best tool for each job. Even if you use IcedCoffeeScript (which is cool), there are still times when Promises will save you a huge amount of work.

    I hope that helps. Check out my book, Async JavaScript, for much more information.