Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
170
Other Decks in Technology
See All in Technology
MCPゲートウェイを作って運用してわかったこと — Agent時代の権限管理の現在地
mtpooh
10
3.2k
おそらく日本で唯一のDevRelインターン生として
husengs7
0
170
OpenSharing について熱く語る〜AI アセットの共有について〜
kameitomohiro
0
240
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
160
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
0
160
実践! SRE × AI - ABEMA における AIOps -
tetsuya28
7
1.7k
2026-10-01_MagicPod_QAハーネスエンジニアリングとQA組織の未来像
ynisqa1988
1
560
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
720
AI時代に必要な脅威モデリング― 変化の速度に負けない理解とリスク判断
masakane55
5
1.2k
今こそ知りたいAmplifyGen2
mkdev10
2
160
全PRの83%が AIレビューだけでマージできるようになった開発組織は その後どうなったか @2026/10
athug
0
130
オブザーバビリティを高める AI エージェント体験を考える / Designing AI Agent Experiences That Enhance Observability
aoto
PRO
2
320
Featured
See All Featured
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
550
Paper Plane
katiecoart
PRO
4
54k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
720
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
310
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Skip the Path - Find Your Career Trail
mkilby
1
250
The browser strikes back
jonoalderson
0
1.8k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Building an army of robots
kneath
307
47k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
250
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
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!