Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
jQuery Deferreds and Promises
Search
Eli Perelman
November 01, 2011
Technology
400
10
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
jQuery Deferreds and Promises
My introduction slides from the Omaha Front-end Web and jQuery meetup on November 1, 2011.
Eli Perelman
November 01, 2011
More Decks by Eli Perelman
See All by Eli Perelman
Intro to Raptor
eliperelman
0
140
UI Synchronicity
eliperelman
1
160
Other Decks in Technology
See All in Technology
【Oracle AI Spotlight ウェビナー】AWSか、Azureか、Google Cloudか。その議論にオラクルを含める意義。
oracle4engineer
PRO
1
200
bet_ai_day_2026_session02
agenticsec
1
700
PdMをやめて、 "プロダクトビルダー"という 働き方に変えました / PdM to Product Builder
shikichee
2
640
Digitization部 紹介資料
sansan33
PRO
2
7.8k
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
20k
生成AI時代の クレデンシャルとパーミッション設計
nrinetcom
PRO
3
1.3k
いま、生成AIにKaggleをどこまで 任せられるか — ROGIIコンペでの進め方とTips
k951286
1
1.2k
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
55k
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
140
Bet AI Day 2026丨How We Bet AI: AIとともに働く場をつくる
layerx
PRO
1
1.7k
データエンジニアの困りごとをDevinと一緒に解消する
10xinc
2
610
[RSJ26] Flow as Flow: Modeling Robot Velocity Fields as Probability Velocity Fields
keio_smilab
PRO
0
180
Featured
See All Featured
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
260
Are puppies a ranking factor?
jonoalderson
2
3.9k
Building AI with AI
inesmontani
PRO
1
1.2k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
410
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
570
How STYLIGHT went responsive
nonsquared
100
6.3k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
260
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Navigating Team Friction
lara
192
16k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Evolving SEO for Evolving Search Engines
ryanjones
0
280
Transcript
jQuery Deferreds & Promises Eli Perelman @eliperelman
What are deferreds?
Provide a system to register callbacks into neatly managed queues
DEFERREDS
WITHOUT DEFERREDS var validateUser = function ( username, password, callback
) { if ( username === ‘bob’ && password === ‘123’ ) { callback( ‘success’ ); } else { callback( ‘failure’ ); } }; validateUser( ‘bob’, ‘123’, function ( result ) { if ( result === ‘success’ ) { location = ‘/dashboard’; } else { showError( ‘Invalid login.’ ); } });
WITH DEFERREDS var validateUser = function ( username, password )
{ var deferred = $.Deferred(); if ( username === ‘bob’ && password === ‘123’ ) { deferred.resolve(); } else { deferred.reject(); } return deferred.promise(); }; validateUser( ‘bob’, ‘123’ ) .done( function () { location = ‘/dashboard’; }) .fail( function () { showError( ‘Invalid login.’ ); });
Deferreds work with synchronous AND asynchronous functions.
Since jQuery 1.5, the $.ajax module uses deferreds.
What are promises?
Provide a common API for consuming code to register callbacks,
sync or async. PROMISES
Deferreds Promises .then .then .done .done .fail .fail .always .always
.reject .resolve .pipe .pipe .promise .promise .isResolved .isRejected
Coding time!