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.

An introduction to jQuery Deferreds

50 pointsby wtildesleyabout 13 years ago

6 comments

Jachabout 13 years ago
Futures (aka Deferreds aka Promises) are indeed cool. For a more general toolbox, check out <a href="https://github.com/coolaj86/futures" rel="nofollow">https://github.com/coolaj86/futures</a><p>What the linked article doesn't show is how you would create your own future objects, which in my point of view is the more useful thing. (I can always specify the error function using the more general $.ajax() so knowing that $.get() finally allows specifying both success and error with futures isn't that useful...). Besides just plain futures, the join and chainify abstractions (and the sequence abstraction that you can of course get elsewhere) from the futures library I linked allow you to create really nice code. Sequences alone heavily reduced my initial frustrations when using Node.
评论 #3814144 未加载
评论 #3816311 未加载
评论 #3813765 未加载
dclowd9901about 13 years ago
I'm finding that, with the aid of Backbone, the Deferred methodology is becoming obsolete. For instance, as mentioned by someone else in these comments, a great use case for Deferred is firing off multiple queries and waiting on their return.<p>You can accomplish this in Backbone, inherently even, by listening to change events in models. In my app, I used the Deferred methodology to begin with, but now that I'm refactoring the site into Backbone, everything is much cleaner (thanks to the additional structure that MVC provides).
评论 #3814745 未加载
kschultsabout 13 years ago
What the article hints at, but doesn't really follow through on, is that you could use this to fire off multiple AJAX calls in parallel and the do something only when all of them have completed.
lifeinafolderabout 13 years ago
Futures/Promises are an interesting technique to do control flow. IMO, there are certain nuances like losing distinction between async/sync calls that work against the technique. I wrote an article about it at: <a href="http://javascriptturnsmeon.com/93769736" rel="nofollow">http://javascriptturnsmeon.com/93769736</a>
kpozinabout 13 years ago
And if you'd like to use the same API in a non-browser environment, Underscore.Deferred is a complete port of jQuery.Deferred and jQuery.when that has no jQuery dependencies: <a href="https://github.com/wookiehangover/underscore.Deferred" rel="nofollow">https://github.com/wookiehangover/underscore.Deferred</a>
sausagefeetabout 13 years ago
&#60;troll&#62;Yeah, Javascript make it one step closer Twisted, 1999&#60;/troll&#62;