function fetchX() {
return 2 + 3
}
function fetchY() {
return 3 + 4
}
function add(xPromise, yPromise) {
return Promise.all([xPromise, yPromise]).then(function(values) {
console.log('第一步')
return values[0] + values[1]
})
}
add(fetchX(), fetchY()).then(function(sum) {
console.log('第二步')
console.log(sum)
})
这段代码中有两层Promise。
打印结果:
第一步
第二步
5