TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using Deferreds in jQuery 1.5

41 pointsby bretthopperover 14 years ago

3 comments

russell_hover 14 years ago
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<p><pre><code> // this might execute before the $.get() above is complete </code></pre> and<p><pre><code> // something additional to execute upon success, which might, or might not, // have fired by now. With $.ajax deferreds built-in, it doesn't matter. </code></pre> 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".<p>Someone please correct me if I'm wrong on this.
评论 #2163306 未加载
评论 #2166119 未加载
dhimesover 14 years ago
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.
评论 #2164288 未加载
bergieover 14 years ago
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 :-)<p><a href="https://github.com/bergie/midgardmvc_ui_create/blob/master/static/js/editable.js#L255" rel="nofollow">https://github.com/bergie/midgardmvc_ui_create/blob/master/s...</a>