1. How to change the state of promise?

1. Resolve (value): Resolved (pity) 2. Reject (reason): Rejected (pity ③ Raise an exception: If the value is pending, it changes to Rejected

2. Does a promise specify multiple success/failure callbacks that will be called?

This is called whenever a promise changes to the corresponding state

let p = new Promise((resolve,reject) = > {
    resolve("ok")})// Specify callback 1
p.then(value= >{
    console.log(value)
})
// Specify callback 2
p.then(value= >{
    console.log('ha ha')})Copy the code
3. Change the state and specify the order in which callbacks are executed.

(1) It’s all possible. It is normal to specify a callback and then change the state, but it is possible to change the state and then specify a callback. (2) How do I change the state and then specify a callback? (note that this is not specified call) (1) direct calls to resolve in the actuators/reject () () (2) calls for a delay more then () (3) when it’s time to get the data (in the end when the callback function) (1) if the specified callback, first state changes, the callback function is invoked, (2) If the state changes first, the callback function will be called when the callback is specified, and the data summary will be executed after the state changes

4. What determines the result state of the new promise returned by promise.then()?

The result of the callback function specified by then() is determined by the result of the callback function executed by then() When the promise is resolved and value is resolved, the new promise will be resolved and value will be resolved. When the promise is resolved, the new promise will be resolved and value will be resolved. The result of this promise becomes the result of the new promise

Console. log(result) The result is as follows

5. How does promise string together multiple action tasks?

(1) A promise’s then() returns a new promise, which can be thought of as a chained call to then()

6. Abnormal penetration of promise?

(1) When using a promise’s then chain invocation, the failed callback can be specified at the end, and (2) any previous exception is passed to the last failed callback

If you break the promise chain?

(1) When using the promise then chain call, interrupt in the middle, no longer call the following callback method: return a pendding promise object in the callback function (there is only one method)