JS宏任务和微任务

  微任务=>DOM渲染=>宏任务    

1
2
3
4
5
6
7
8
9
10
11
12
13
setTimeout(function(){
   console.log("定时任务")
})
new Promise((resolve)=>{
    console.log("1 promise 1") //同步
    resolve();
}).then(()=>{
    console.log("微任务1")
}).then(()=>{
    console.log('微任务2')
})
 
console.log("同步数据")

  结果:

1 promise 1
同步数据
微任务1
微任务2
定时任务

posted @   不再犯错  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
历史上的今天:
2020-04-03 mysql 查询表字段说明
点击右上角即可分享
微信分享提示