พร้อมมิสภายในสายโซ่ใน JavaScript

ฟังก์ชันในสายโซ่สามารถส่งคืนพรอมมิสได้ด้วย ในกรณีนี้ผลลัพธ์ของพรอมมิสนี้จะถูกส่งต่อไปยัง then ถัดไป:

javascriptpromise.then(
  function(result) {
    return result + '1';
  }
).then(
  function(result) {
    return new Promise(function(resolve) {
      resolve(result + '2'); // ผลลัพธ์นี้จะไปยัง then ถัดไป
    });
  }
).then(
  function(result) {
    return result + '3';
  }
).then(
  function(result) {
    console.log(result); // จะแสดง 'string123'
  }
);