Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
10
370
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
Tweet
Share
More Decks by Eli Perelman
See All by Eli Perelman
Intro to Raptor
eliperelman
0
120
UI Synchronicity
eliperelman
1
130
Other Decks in Technology
See All in Technology
タグ付きユニオン型を便利に使うテクニックとその注意点
uhyo
2
700
Uncertainty in the LLM era - Science, more than scale
gaelvaroquaux
0
630
事業部のプロジェクト進行と開発チームの改善の “時間軸" のすり合わせ
konifar
9
3.1k
AI (LLM) を活用する上で必須級のMCPをAmazon Q Developerで学ぼう / 20251127 Ikuma Yamashita
shift_evolve
PRO
2
110
グレートファイアウォールを自宅に建てよう
ctes091x
0
120
【AWS re:Invent 2025速報】AIビルダー向けアップデートをまとめて解説!
minorun365
2
300
生成AI・AIエージェント時代、データサイエンティストは何をする人なのか?そして、今学生であるあなたは何を学ぶべきか?
kuri8ive
2
1.9k
なぜフロントエンド技術を追うのか?なぜカンファレンスに参加するのか?
sakito
9
2k
.NET 10 のパフォーマンス改善
nenonaninu
2
4.8k
法人支出管理領域におけるソフトウェアアーキテクチャに基づいたテスト戦略の実践
ogugu9
1
180
原理から解き明かす AIと人間の成長 - Progate BAR
teba_eleven
2
300
HIG学習用スライド
yuukiw00w
0
110
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
697
190k
Producing Creativity
orderedlist
PRO
348
40k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.3k
Why Our Code Smells
bkeepers
PRO
340
57k
Stop Working from a Prison Cell
hatefulcrawdad
273
21k
Testing 201, or: Great Expectations
jmmastey
46
7.8k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
Balancing Empowerment & Direction
lara
5
790
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.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!