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
160
Other Decks in Technology
See All in Technology
Fラン学生が考える、AI時代のデザインに執着した突破口
husengs7
1
240
実例から学ぶ GuardDuty(SSH BruteForce)調査の全体フローと勘所【SecurityJAWS】
cscengineer
PRO
0
190
ソフトウェアサプライチェーン攻撃対策として今からサクッとできること
flatt_security
2
110
GitHub Copilot CLI の Rubber Duck 機能を使ってコーディングの品質をあげよう #techbaton_findy
stefafafan
2
460
SDDで⾒える、AIコーディングの"内訳"
lycorptech_jp
PRO
0
150
情シスがMCP環境導入時に打ちのめされる認可の崖
oidfj
0
180
TypeScriptはどのようにどこまで推論できるのか ─ とにかく as は禁止で
ypresto
1
310
LookerとADKで作る社内AIエージェント
chanyou0311
0
290
パーソルキャリア IT/テクノロジー職向け 会社紹介資料|Company Introduction Deck
techtekt
PRO
0
260
Claude Code で使える DuckDB Skills を試してみた / DuckDB Skills and Claude Code
masahirokawahara
1
2.1k
ジュニアエンジニアはSREとどう向き合うべきか
nrinetcom
PRO
0
110
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.4k
Featured
See All Featured
Building Adaptive Systems
keathley
44
3k
From π to Pie charts
rasagy
0
180
GraphQLとの向き合い方2022年版
quramy
50
15k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.2k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
450
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
SEO for Brand Visibility & Recognition
aleyda
0
4.5k
Crafting Experiences
bethany
1
150
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Design in an AI World
tapps
1
210
A Soul's Torment
seathinner
6
2.8k
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!