zoukankan      html  css  js  c++  java
  • Promise调用方式

    //第一种调用方式
    new Promise((resolve,reject)=>{
      setTimeout(function() {
        console.log('模拟异步请求操作!');
        //resolve('成功时主动调用这个函数,会执行下面的then方法')
       // reject('失败时主动调用这个函数,会执行下面的catch方法')
      },1000);
    }).then(data=>{
      //成功后的处理代码
      console.log(data);
      //这里执行完毕后可以继续new Promise进行链式调用
      new Promise((resolve,reject)=>{}).then();
    }).catch(err=>{
      //失败后的处理代码
      console.log(err);
    })
    //第二种写法
    new Promise((resolve,reject)=>{
      setTimeout(function() {
        console.log('模拟异步请求操作!');
        //resolve('成功时主动调用这个函数,会执行下面的then方法')
       // reject('失败时主动调用这个函数,会执行下面的catch方法')
      },1000);
    }).then(data=>{
      //成功后的处理代码
      console.log(data);
      //这里执行完毕后可以继续new Promise进行链式调用
      new Promise((resolve,reject)=>{}).then();
    },err=>{
      //失败后的处理代码
      console.log(err);
    })
  • 相关阅读:
    读写文件print函数操作
    协程相关
    线程池
    多线程条件
    ibm动态测试
    ubuntu 之 搜狗拼音安装
    Linux 安装 出现Could not get lock /var/lib/dpkg/lock
    Sql server
    maven 搭建
    EOS
  • 原文地址:https://www.cnblogs.com/jiangyunfeng/p/13401871.html
Copyright © 2011-2022 走看看