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
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
OSSで構築するIT基盤管理実践事例: NetBox・Snipe-IT・FreeRADIUS+PrivacyIDEA / Practical Case Studies of IT Infrastructure Management Using OSS
nttcom
0
200
生成AI活用によるPRレビュー改善の歩み
lycorptech_jp
PRO
5
2k
プロジェクトマネジメントをチームに宿す -ゼロからはじめるチームプロジェクトマネジメントは活動1年未満のチームの教科書です- / 20260304 Shigeki Morizane
shift_evolve
PRO
1
110
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
14k
Serverless Agent Architecture on Azure / serverless-agent-on-azure
miyake
1
150
「使いにくい」も「運用疲れ」も卒業する UIデザイナーとエンジニアが創る持続可能な内製開発
nrinetcom
PRO
1
780
トップマネジメントとコンピテンシーから考えるエンジニアリングマネジメント
zigorou
3
540
ヘルシーSRE
tk3fftk
2
240
白金鉱業Meetup_Vol.22_Orbital Senseを支える衛星画像のマルチモーダルエンベディングと地理空間のあいまい検索技術
brainpadpr
2
210
新職業『オーケストレーター』誕生 — エージェント10体を同時に回すAgentOps
gunta
4
1.4k
チームメンバー迷わないIaC設計
hayama17
5
3.8k
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
72k
Featured
See All Featured
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
170
Information Architects: The Missing Link in Design Systems
soysaucechin
0
810
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
450
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
220
Color Theory Basics | Prateek | Gurzu
gurzu
0
230
KATA
mclloyd
PRO
35
15k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
How STYLIGHT went responsive
nonsquared
100
6k
Amusing Abliteration
ianozsvald
0
120
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.1k
Building Adaptive Systems
keathley
44
2.9k
We Are The Robots
honzajavorek
0
190
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!