What is the principle of chain invocation of Promise?

everyone knows that the chained call to jQuery is a wonderful use for return this, but what about Promise? For example,

function start() {  
    return new Promise((resolve, reject) => {  
      resolve("start");  
    });  
  }  
    
  start()  
    .then(data => {  
      // promise start  
      console.log("result of start: ", data);  
      return Promise.resolve(1); // p1  
    })  
    .then(data => {  
      // promise p1  
      console.log("result of p1: ", data);  
      return Promise.reject(2); // p2  
    })  
    .then(data => {  
      // promise p2  
      console.log("result of p2: ", data);  
      return Promise.resolve(3); // p3  
    })  
    .catch(ex => {  
      // promise p3  
      console.log("ex: ", ex);  
      return Promise.resolve(4); // p4  
    })  
    .then(data => {  
      // promise p4  
      console.log("result of p4: ", data);  
    });  

result of start: start
result of p1: 1
ex: 2
result of p4: 4

the third step, reject is also ignored by the next step of then. What is the principle of this chained call? How did it happen?


your analogy is not appropriate.

third step, reject is also ignored by then in the next step
The correct way to say

is that the call of then is not ignored, but the callback in then is ignored is executed.

just try the following code:

  article  has a related exposition, you can refer to 

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e484ac-441e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e484ac-441e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?