文章 评论 浏览 30
我是这样理解的 await 的:
await 后面的函数,就像是 Promise 接收的 executor 参数一样,都是立即同步执行的;await 函数之后的代码,就像是 Promise.then 的回调一样,都属于是 micro task;
function print(n){ setTimeout(() => { console.log(n); }, Math.floor(Math.random()+1) * 1000); } for(var i = 0; i < 100; i++){ print(i); }
文章 0 评论 0
接受
我是这样理解的 await 的:
await 后面的函数,就像是 Promise 接收的 executor 参数一样,都是立即同步执行的;
await 函数之后的代码,就像是 Promise.then 的回调一样,都属于是 micro task;
第 10 题:常见异步笔试题,请写出代码的运行结果