promise
本身 —同步
例子:
let obj=new Promise((res,rej)=>{
console.log('这是promise对象');
});
console.log('哼哼');
效果展示
分析:由此可见,promis对象本身是同步
promise
的回调函数then
--异步
例子:
let obj=new Promise((res,rej)=>{
console.log('这是promise本身');
res('这是回调函数then的值')
});
obj.then((res) => {
console.log(res);
});
console.log('哼哼');
效果展示:
分析:promise.then()—回调函数中的内容是异步函数