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的执行流程和跳转方法
posted on 2016-07-18 17:38 阅读( ...) 评论( ...)