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
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_Dev_Ex2026_AI_登壇資料
matsuritechnologies
PRO
2
590
ソフトウェアアーキテクチャ研修【MIXI 26新卒技術研修】
mixi_engineers
PRO
2
150
OPENLOGI Company Profile for engineer
hr01
1
75k
論語・武士道・産業革命から見る かわるもの、かわらないもの
ichimichi
7
780
プロダクト開発組織の現在地(Ver.2026/07) / product-organization
kaonavi
0
470
CloudWatchから始めるAWS監視
butadora
0
130
事業成長とAI活用を止めないデータ基盤アーキテクチャの設計思想
hiracky16
0
700
Claude CodeとAmazon Bedrock AgentCoreでつくる、自分だけのAIアシスタント
ymae
0
110
Aurora MySQL 8.4リリース! Rubyistが備えること / what-rubyist-should-prepare-for-aurora-mysql-8-4
fkmy
0
1.2k
Vポイント分析基盤におけるデータモデリング20年史
taromatsui_cccmkhd
4
760
VPCセキュリティ対応の最新事情
nagisa53
1
320
そのドキュメント、自動化しませんか?
yuksew
1
430
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
660
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
The Limits of Empathy - UXLibs8
cassininazir
1
540
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
810
Optimising Largest Contentful Paint
csswizardry
37
3.8k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
390
A Modern Web Designer's Workflow
chriscoyier
698
190k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
840
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
620
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
460
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!