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
390
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
160
Other Decks in Technology
See All in Technology
非定型業務をAI slackbotで自動化する ~ 社内要望を自動壁打ちするbotを作った ~/automating-ad-hoc-work-with-ai-slackbot
shibayu36
0
350
「コーディング」しない人のための Claude Code 入門 ChatGPT の次の一歩 — 業務に組み込む 育成・共有・自動化
rfdnxbro
2
1.2k
AIプラットフォームを運用し続けるための可観測性
tanimuyk
4
1.2k
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
28
20k
AI Adaptable なテストを整える工夫 / Ways to Make Your Tests AI-Adaptable
bitkey
PRO
3
220
AI Engineering Summit Tokyo 2026 AIの前に、やることがある 〜医療データ企業の4フェーズ〜
dtaniwaki
0
2.2k
機械学習を「社会実装」するということ 2026年夏版 / Social Implementation of Machine Learning June 2026 Version
moepy_stats
2
160
Dynamic Workersについて
yusukebe
2
630
[モダンアプリ勉強会]今更聞けないGit/GitHub入門
tsukuboshi
0
300
React、まだ楽しくて草
uhyo
7
4.2k
DevOps Agentで始めるAWS運用 〜フロンティアエージェントが変える運用の現場〜
nyankotaro
1
320
GoとSIMDとWasmの今。
askua
3
520
Featured
See All Featured
Navigating Weather and Climate Data
rabernat
0
210
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Odyssey Design
rkendrick25
PRO
2
690
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
850
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
600
AI: The stuff that nobody shows you
jnunemaker
PRO
8
690
Into the Great Unknown - MozCon
thekraken
41
2.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
720
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.3k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
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!