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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Eli Perelman
November 01, 2011
Technology
400
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
ホームラボ紹介
y_sera15
0
180
老害フォレンジッカーはAI羊の夢を見るか?
tadmaddad
0
330
MIRU 2026 チュートリアル
keisuke198619
0
920
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
120
攻撃と防御で学ぶAI時代のプロダクトセキュリティ演習
recruitengineers
PRO
9
2.9k
AIペネトレーションテスト・ セキュリティ検証「AgenticSec」紹介資料
laysakura
2
9k
Flutterをカメラで動かしたかった話
sony
1
140
AI-DLC実践録_フルサイクル開発への挑戦
miyuc
0
110
JavaScript 研修 (2026)
recruitengineers
PRO
2
560
LLM・AIエージェントシステムベストプラクティス
shibuiwilliam
6
1.3k
修正PRを食べてレビュースキルが賢くなる:Claude Codeによる自己改善サイクル
yuyaumetsu
6
1.5k
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.9k
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The agentic SEO stack - context over prompts
schlessera
0
860
Art, The Web, and Tiny UX
lynnandtonic
304
22k
GraphQLとの向き合い方2022年版
quramy
50
15k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Building Adaptive Systems
keathley
44
3.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Color Theory Basics | Prateek | Gurzu
gurzu
0
420
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!