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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Eli Perelman
November 01, 2011
Technology
10
390
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
130
UI Synchronicity
eliperelman
1
150
Other Decks in Technology
See All in Technology
A Casual Introduction to RISC-V
omasanori
0
440
今のWordPress の制作手法ってなにがあんねん?(改) / What’s the Deal with WordPress Development These Days?
tbshiki
0
520
Agent ServerはWeb Serverではない。ADKで考えるAgentOps
akiratameto
0
120
ソフトバンク流!プラットフォームエンジニアリング実現へのアプローチ
sbtechnight
1
220
OCI技術資料 : コンピュート・サービス 概要
ocise
4
54k
Go 1.26 Genericsにおける再帰的型制約 / Recursive Type Constraints in Go 1.26 Generics
ryokotmng
0
140
実践 Datadog MCP Server
nulabinc
PRO
2
250
Tebiki Engineering Team Deck
tebiki
0
27k
AlloyDB 奮闘記
hatappi
0
170
「お金で解決」が全てではない!大規模WebアプリのCI高速化 #phperkaigi
stefafafan
4
1.7k
会社紹介資料 / Sansan Company Profile
sansan33
PRO
16
410k
NewSQL_ ストレージ分離と分散合意を用いたスケーラブルアーキテクチャ
hacomono
PRO
4
410
Featured
See All Featured
Test your architecture with Archunit
thirion
1
2.2k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.5k
KATA
mclloyd
PRO
35
15k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
480
How to Ace a Technical Interview
jacobian
281
24k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
830
Rails Girls Zürich Keynote
gr2m
96
14k
A Tale of Four Properties
chriscoyier
163
24k
We Have a Design System, Now What?
morganepeng
55
8k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Into the Great Unknown - MozCon
thekraken
40
2.3k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
180
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!