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
130
Other Decks in Technology
See All in Technology
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
3.3k
Noを伝える技術2025: 爆速合意形成のためのNICOフレームワーク速習 #pmconf2025
aki_iinuma
2
1.4k
タグ付きユニオン型を便利に使うテクニックとその注意点
uhyo
2
680
Data Hubグループ 紹介資料
sansan33
PRO
0
2.3k
AI駆動開発によるDDDの実践
dip_tech
PRO
0
300
バグハンター視点によるサプライチェーンの脆弱性
scgajge12
2
550
Claude Code Getting Started Guide(en)
oikon48
0
150
Symfony AI in Action
el_stoffel
2
370
生成AI時代の自動E2Eテスト運用とPlaywright実践知_引持力哉
legalontechnologies
PRO
0
150
私のRails開発環境
yahonda
0
180
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
pmconf2025 - データを活用し「価値」へ繋げる
glorypulse
0
510
Featured
See All Featured
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
A better future with KSS
kneath
240
18k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.6k
Navigating Team Friction
lara
191
16k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
120
20k
Six Lessons from altMBA
skipperchong
29
4.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
A Modern Web Designer's Workflow
chriscoyier
697
190k
Site-Speed That Sticks
csswizardry
13
990
Producing Creativity
orderedlist
PRO
348
40k
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!