News for hackers. Stuff that matters.
Re:Using Deferreds in jQuery 1.5 by russell_h on Monday January 31, 2011 @03:29PM (#2163035)
I don't know much about browser-side javascript, but unless they're doing something really weird in the event loop I believe the comments

    // this might execute before the $.get() above is complete
and

    // something additional to execute upon success, which might, or might not,
    // have fired by now.  With $.ajax deferreds built-in, it doesn't matter.
are misleading. In fact, the first comment should read "this will execute before the $.get() above is complete" and the second one should read "which will not have fired yet".

Someone please correct me if I'm wrong on this.

Re:Using Deferreds in jQuery 1.5 by mrkurt on Monday January 31, 2011 @04:44PM (#2163306)
You're not wrong in terms of the sample code, but in general the "success" method might be called after the request is complete. It's like the "ready" event in jQuery, you're meant to use that even after the DOMReady has fired.
Re:Using Deferreds in jQuery 1.5 by ehynds on Tuesday February 01, 2011 @11:42AM (#2166119)
Not if things are in the cache, especially in IE. In this case the xhr will complete almost immediately.
Re:Using Deferreds in jQuery 1.5 by dhimes on Monday January 31, 2011 @05:07PM (#2163404)
For a single ajax request this doesn't save much (just call the functions you need to call from the success() method). In fact, if used poorly it may obfuscate the program flow. However, the "when" example looks interesting. I'm new to JS and JQ, so I haven't run into that problem yet (and known it!), but at this point I would have to, for each ajax query, set some sort of "state" bool and call the function I want to run. Only when all the bools were set to true- meaning all calls found success- would the function execute. The "when" approach is much more elegant.
Re:Using Deferreds in jQuery 1.5 by wahnfrieden on Monday January 31, 2011 @10:23PM (#2164288)
You might also be interested to know that Dojo has DeferredList for tracking several Deferred objects (the equivalent of jQuery promises). The DeferredList is itself a Deferred which is activated once all the Deferreds in it execute.
Re:Using Deferreds in jQuery 1.5 by bergie on Monday January 31, 2011 @03:36PM (#2163057)
Ah, great. I had a situation today where the when/then deferred would've simplified my code quite a bit. Now I just need to upgrade jQuery and clean up the quick hack I did in the place :-)

https://github.com/bergie/midgardmvc_ui_create/blob/master/s...