Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
10
370
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
Tweet
Share
More Decks by Eli Perelman
See All by Eli Perelman
Intro to Raptor
eliperelman
0
120
UI Synchronicity
eliperelman
1
140
Other Decks in Technology
See All in Technology
エンジニアリングをやめたくないので問い続ける
estie
2
1.2k
ディメンショナルモデリングを支えるData Vaultについて
10xinc
1
100
WordPress は終わったのか ~今のWordPress の制作手法ってなにがあんねん?~ / Is WordPress Over? How We Build with WordPress Today
tbshiki
1
800
プロンプトやエージェントを自動的に作る方法
shibuiwilliam
12
10k
AIプラットフォームにおけるMLflowの利用について
lycorptech_jp
PRO
1
170
Python 3.14 Overview
lycorptech_jp
PRO
1
120
re:Invent2025 コンテナ系アップデート振り返り(+CloudWatchログのアップデート紹介)
masukawa
0
390
AWS CLIの新しい認証情報設定方法aws loginコマンドの実態
wkm2
6
750
Snowflakeでデータ基盤を もう一度作り直すなら / rebuilding-data-platform-with-snowflake
pei0804
6
1.6k
IAMユーザーゼロの運用は果たして可能なのか
yama3133
1
460
OCI Oracle Database Services新機能アップデート(2025/09-2025/11)
oracle4engineer
PRO
1
210
Sansanが実践する Platform EngineeringとSREの協創
sansantech
PRO
2
910
Featured
See All Featured
Docker and Python
trallard
47
3.7k
Automating Front-end Workflow
addyosmani
1371
200k
Music & Morning Musume
bryan
46
7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
What's in a price? How to price your products and services
michaelherold
246
13k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Mobile First: as difficult as doing things right
swwweet
225
10k
A Tale of Four Properties
chriscoyier
162
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
How to train your dragon (web standard)
notwaldorf
97
6.4k
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!