zoukankan      html  css  js  c++  java
  • js中的微任务和宏任务

    • 微任务 promise 、async await

      • 微任务 遇到微任务,放在当前任务列的最底端(then或者catch里面的内容)

    • 宏任务 setTimeout setInterval

      • 宏任务 遇到宏任务,放到下一个新增任务列的最顶端

    • 当前任务列执行完成了再去执行下一个任务列

      • 当then和then的外层都有宏任务时,先创建外层的宏任务

    Promise.resolve().then(function () {
            console.log(1);
            Promise.resolve().then(function () {
              console.log(2);
            });
            Promise.resolve().then(function(){
                console.log(3);
            });
          });
          Promise.resolve().then(function(){
              console.log(4);
          })//1423
    
        async function fn(){
              console.log(1);
              await Promise.resolve().then(function(){
                  console.log(2);
              })
              await Promise.resolve().then(function(){
                  return 3;
              });
              await Promise.resolve().then(function(){
                  console.log(4);
              })
          }
          fn().then(function(num){
              console.log(num);
          })//124underfined
    
          console.log(0);
          setTimeout(console.log(1),0);//这个里面执行的是代码块不是语句块,直接执行就OK了
          console.log(2);
          //012
  • 相关阅读:
    软件测试人员的要求
    冒烟测试和回归测试的区别
    [go]struct
    [go]socket编程
    [go]gorhill/cronexpr用go实现crontab
    [go]os/exec执行shell命令
    [go]time包
    [go]etcd使用
    [go]redis基本使用
    [go]go操作mysql
  • 原文地址:https://www.cnblogs.com/shewill/p/13051359.html
Copyright © 2011-2022 走看看