为什么我的输出有100?
源代码:
console.log('start');
new Promise(resolve => {
console.log('Step 1');
setTimeout(() => {
resolve(100);
}, 1000);
}).then(value => {
return new Promise(resolve => {
console.log(value);
console.log('Step 1-1');
setTimeout(() => {
resolve(110);
}, 1000);
}).then(value => {
console.log('Step 1-2');
return value;
}).then(value => {
console.log('Step 1-3');
return value;
});
}).then(value => {
console.log(value);
console.log('Step 2');
});
控制台输出:
D:\Dev\node-v12.13.0-x64\node.exe sample\nested-then.js
start
Step 1
100
Step 1-1
Step 1-2
Step 1-3
110
Step 2
2