Open LLwanran opened 5 years ago
这里对上面的例子做一个扩展
const promise = new Promise((resolve, reject) => {
console.log(1);
resolve(5);
console.log(2);
}).then(val => {
console.log(val);
});
promise.then(() => {
console.log(3);
});
console.log(4);
setTimeout(function() {
console.log(6);
});
执行结果: 124536
执行结果是:1243 promise构造函数是同步执行的,then方法是异步执行的