美文网首页
async原理

async原理

作者: 月肃生 | 来源:发表于2019-05-09 15:37 被阅读0次

async 用法

async function A() {
  let a = await 1;
  console.log(a);
  let b= await Promise.resolve(2);
  console.log(b);
  return 3;
}

转码理解

function A() {
  var a;
  var b;
  return new Promise(function(resolve){
    a = 1;
    console.log(a);
    resolve();
  }).then(function(){
    Promise.resolve(2).then(res => {
      b = 2;
      console.log(b)
    });
  }).then(() => 3)
}

相关文章

网友评论

      本文标题:async原理

      本文链接:https://www.haomeiwen.com/subject/iqqwoqtx.html