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的执行流程和跳转方法
原文地址:https://www.cnblogs.com/william-lin/p/5682102.html