• 再次理解promise


    总结:then中的代码是同步执行的即使是链式调用也是如此。但then中的回调函数一定要等待前面返回promise结果才能执行。

      const a = new Promise((resolve, reject) => {
          console.log(2);
        }).then(function x() {
          console.log(5);
        }).then(console.log(111))
        // // 2,111
    
        const b = new Promise((resolve, reject) => {
          resolve(1)
          console.log(2);
        }).then(function x() {
          console.log(5);
        }).then(console.log(111))
        // // 2,111,5   //链式调用.then时并不是后面的then一定要等前面返回结果才会执行。在链式调用中.then也是遵循then中代码同步执行;
                        //需要注意的是:.then中如果是回调函数的话,一定需要等待前面返回promise状态后才能执行。
    
        const c = new Promise((resolve, reject) => {
          resolve(1)
          console.log(2);
        }).then(function x() {
          console.log(5);
        }).then(function x() {
          console.log(111);
        })
        //2,5,111
    
        const c = new Promise((resolve, reject) => {
          console.log(2);
        }).then(
          console.log(5)
        ).then(function x() {
          console.log(111);
        })
       //2,5
    
  • 相关阅读:
    洛谷P1182 数列分段`Section II`
    洛谷P3902 递增
    洛谷P1678-烦恼的高考志愿
    POJ 3263-Tallest Cow
    洛谷P2280 [HNOI2003]激光炸弹
    POJ 1958
    Vijos 1197
    VirtualBox 导入.vdi文件时报“uuid is exists”错误
    解压常用
    cut 命令
  • 原文地址:https://www.cnblogs.com/xjt31/p/13996409.html
Copyright © 2020-2023  润新知