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的执行流程和跳转方法

相关文章:

  • 2021-11-19
  • 2021-07-15
  • 2021-05-02
  • 2022-01-08
  • 2021-09-27
  • 2021-09-01
  • 2021-12-13
  • 2021-07-12
猜你喜欢
  • 2021-05-17
  • 2021-12-01
  • 2021-12-03
  • 2021-11-30
  • 2021-12-19
相关资源
相似解决方案