const a = new Promise(function(resolve,reject){
console.log(1);
resolve()
});
a.then(function(){
console.log(2);
return Promise.resolve("data");
}).then(function(data){
console.log(data)
console.log(3);
});
a.then(function(){
console.log(4);
}).then(function(){
console.log(8)
});
setTimeout(function(){
console.log(5);
a.then(function(){
console.log(6)
});
console.log(7)
},2000)
// 结果:1 2 4 8 3 5 7 6
new Promise((resolve) =>{
Promise.resolve(4).then(resolve)
}).then(function(){console.log(444)})
new Promise((resolve) => {
resolve(4)
}).then(function(){console.log(555)});
//思考:promise的then,
/*
当promise状态为resolved时会立即将回调函数添加到微任务队列,否则就在后面变为resolved后添加到微任务队列;
当回调执行完毕,拿到回调的返回值,重新包装一个promise返回,当返回值为非promise对象,直接返回一个resolved状态的promise,否则new 一个promise,其resolve回调在 返回值的then里面执行;
*/