zoukankan      html  css  js  c++  java
  • Promise 使用心得

        this.testPromise=function(){
            return new Promise(function(resolve,reject){
                console.log("testPromise start:");
                resolve(true);     //这里会将true传到下一个then的参数s中
            });
           
        }
        this.testPromise()
            .then(function(s){
                console.log("testPromise 1");
                try{
                    var aa=123123;
                    aa='12aa312313';
                    adfd;
                }
                catch(e){
                    return false;     //因为adfd出错会执行cath代码块,return 会跳出这个then然后传递false给下一个then,同时就不会再执行后面的if
                }

                if (s) {
                    console.log("testPromise 1 true");
                    Promise.resolve(false);
                }
            })
            .then(function(s){
                console.log("testPromise 2");
                console.log(s);     //到这里s的值就是false

            });
     
    这段代码主要是给示例一下promise的执行流程和跳转方法
  • 相关阅读:
    MySQL数据库命令行界面不支持中文
    mysqldump使用方法(MySQL数据库的备份与恢复)
    MySQL性能测试初试(1)--sysbench
    composer安装
    Java关键字[static].md
    Docker容器
    Docker概述及安装
    Docker镜像
    定时任务[crontab]
    Linux下的curl工具
  • 原文地址:https://www.cnblogs.com/william-lin/p/5682102.html
Copyright © 2011-2022 走看看