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をフル活用してオンコール機能のプロトタイプを2日で作った話 / Building an AI-Powered On-Call Prototype in Just Two Days
nari_ex
0
160
製造現場での生成AIの活用、およびエージェントAIの実装のあり方、AVEVAの取り組み
iotcomjpadmin
0
210
Zenoh on Zephyr on LiteX
takasehideki
2
160
#エンジニアBooks 30分でわかる 「技術記事を書く技術」 / engineer-books 2026-06-30
jnchito
1
150
Microsoft のサポートとフィードバック総まとめ
murachiakira
PRO
0
130
背中から、背中へ /paying forward to community
naitosatoshi
0
190
PostgreSQL 19 新機能概要 OSC Hokkaido 2026
nori_shinoda
0
260
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
260
作る力から、見極める力へ — AI時代に広がるエンジニアの価値と役割
rince
0
390
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
110
勉強会企画をアプリで構造化してみた 〜そこで見えた、AIとの付き合い方〜 / I've structured a study group plan using an app.
pauli
0
230
FinOps X 2026 Recap from Engineer Side #JapanFinOps
chacco38
0
210
Featured
See All Featured
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
480
The browser strikes back
jonoalderson
0
1.3k
GraphQLとの向き合い方2022年版
quramy
50
15k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
400
Done Done
chrislema
186
16k
Tell your own story through comics
letsgokoyo
1
980
Navigating Team Friction
lara
192
16k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
180
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
620
How to Think Like a Performance Engineer
csswizardry
28
2.7k
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!