/** * Promise 使用 .then 串接 * 在 .then 裡面 revole(value) 的 value 一樣是 promise 物件, * 可以被傳到下一個 .then 中使用。 **/ const chainPromise = new Promise((resolve, reject) => { console.log('In new Promise, start callback') // 會立即執行 setTimeout(() => { let data = 10 resolve(data) // 1 秒後執行 }, 1000) }) chainPromise.then((value) => { console.log('first .then') // 被 resolve 後執行 return value + 3 }) .then((value) => { // 得到上一個 .then return 的值後執行 console.log('second .then') console.log('The final value is ' + value) })