Detailed explanation of promise method

1.What is a promise?

image.png


2. What is callback hell?

image.png

image.png


●Callback hell is actually caused by too many nested callback functions.
3. Basic use of promise
Promise is an es6 syntax. When we create a new promise, we need to pass a callback function, which is executed immediately. Call it (executor)
For this callback function, we need to pass in two parameters reslove reject
When the reslove function is executed, the .then of the promise object will be called back The function .then function can receive both success and failure When the reject function is executed, the .catche function of the promise object will be called back

image.png


4.promise three states

image.png

image.png


5.promise result
The result returned after the request succeeds or fails

image.png


6.Promise resolve method

image.png


7.promise reject method

image.png


8.promise.all method

image.png

image.png


9.promise.race method

image.png


10.promise.allSettled method

image.png


11.promise.any

image.png

---------------------Finished with flowers! ! ! If you find anything useful, please give it a like! !

Guess you like

Origin blog.csdn.net/m0_61043829/article/details/131912180