Javascript Promise Simplified: Revealing The Concept Behind JS Promises
Javascript Promise Simplified: Revealing The Concept Behind JS Promises
%hat is Promise $
Is it Replacement for
Call&ac' $
If es ( %hy $
If Not( %hy $
In my )ords
Provides maintaina&lity
You could create your own promise
Let us begin
Callback chain results into 'Spaghetti code'
Chain of Callbacks in the code frustrate us
doSomething(callback){
var value !"#
callback(!")#
$
callback(anotherCallback){
var value %got frustrated of this chain&
anotheCallback(value)
$
Promise )ay to do
+oSomething,-.then,callBac'
,--.then,anotherCallBac',--
AS" .!RS/01 $$
ho) Promise does the
e*ec#tion $
%hat is 2then2 $
S/CR/3 R/4/A0/+
/*ec#tion
doSomething,-5
66yo#r code
ret#rn5
then7 f#nction,call&ac'-5
var val#e 8 9:;
call&ac',9:-
<
<
<
call&ac',val#e-566yo#r code<
'eally ( ')hen' returns promises *
2then2
3hen accepts t)o f#nction
Resolve,-
Re=ect,-
%hy t)o
f#nctions $
Is it necessary $
PR.MIS/ Have State
S)+),S
resolve
reject
pending
%hy these states $
-on't need to think
Look into previous slide
Still )hinking ( .hy '/ending' State *
0/3 !S 0.." .N 3HIS 0IN" 1.R 1!00 PR.MIS/ C.+/
https766docs.google.com6a6nisostech.com6doc#ment6d6>*4e?@::e?'A@eaPMvA
NoBsoCCI)?rJ.RS"IfBtD0?Bc6edit
E