promise is how come?

A, promise is how to generate  

1. promise is not a new feature, it is a class, it is only for asynchronous programming code to integrate it is to solve the asynchronous (deeply nested relationship), to make your code look cleaner.

2. es6 promise is in a class (constructor), it needs to use the new instance.

note:

  In es5 in class constructor and a meaning, in es6 class is a class constructor is the constructor

3. Just create a promise instance when they are in a pending (in progress) state.

 

 

4. promise constructor accepts a function as a parameter, two parameters are the parameters of resolve and rejected, when you called successfully resolve when you fail to call rejected.

promise to use:

  1. then is successful, catch a failure,

  2. The first function is a function of success, the second is the failure function,

  3. Successful function from the resolve (),

  4. Failure function from reject (),

  5. p1 is stored in the memory, if I want to use it, you need to go through the use of the dot operator,

  6. then if there are two functions, the first one is successful, the second is a failure, if there is a function that is a function of success,

  

 

 

Author: Jin Feixiang
phone number (micro-channel synchronous): 17,812,718,961
hope this article can give is learning the front of friends or friends who work and bring the harvest does not like do not spray where it is proposed a lot of proposals thank you! ! !

Guess you like

Origin www.cnblogs.com/jinfeixiang/p/12195684.html