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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Eli Perelman
November 01, 2011
Technology
390
10
Share
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
150
Other Decks in Technology
See All in Technology
[OpsJAWS 40]リリースしたら終わり、じゃなかった。セキュリティ空白期間をAWS Security Agentで埋める
sh_fk2
3
240
Data Hubグループ 紹介資料
sansan33
PRO
0
2.9k
コミュニティ・勉強会を作るのは目的じゃない
ohmori_yusuke
0
210
AWS DevOps Agentはチームメイトになれるのか?/ Can AWS DevOps Agent become a teammate
kinunori
6
740
AI時代 に増える データ活用先
takahal
0
230
AIを共同作業者にして書籍を執筆する方法 / How to Write a Book with AI as a Co-Creator
ama_ch
2
130
ハーネスエンジニアリングをやりすぎた話 ~そのハーネスは解体された~
gotalab555
4
1.7k
Do Vibe Coding ao LLM em Produção para Busca Agêntica - TDC 2026 - Summit IA - São Paulo
jpbonson
3
120
国内外の生成AIセキュリティの最新動向 & AIガードレール製品「chakoshi」のご紹介 / Latest Trends in Generative AI Security (Domestic & International) & Introduction to AI Guardrail Product "chakoshi"
nttcom
2
750
Claude Code を安全に使おう勉強会 / Claude Code Security Basics
masahirokawahara
10
33k
[最強DB講義]推薦システム | 基礎編
recsyslab
PRO
1
170
プラットフォームエンジニアリングの実践 - AWS コンテナサービスで構築する社内プラットフォーム / AWS Containers Platform Meetup #1
literalice
1
160
Featured
See All Featured
Design in an AI World
tapps
1
200
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.4k
Claude Code のすすめ
schroneko
67
220k
The agentic SEO stack - context over prompts
schlessera
0
750
Discover your Explorer Soul
emna__ayadi
2
1.1k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
210
Navigating Weather and Climate Data
rabernat
0
170
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
490
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
130
Code Reviewing Like a Champion
maltzj
528
40k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
440
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
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!