es6语法总结二Promise
let checkLogin = function () { return new Promise(function (resolve, reject) { let flag = document.cookie.indexOf('userId')>-1?true:false; if(!flag){ console.log(flag) resolve({ status:0, result:true }) }else { reject('error000'); } }) }; let getUserInfo = () => { return new Promise((resolve,reject)=>{ let userInfo = { userId:'101' }; resolve({userInfo}); }); } checkLogin().then(function (res) { if(res.status==0){ console.log('login succsess'); return getUserInfo(); } }).catch((error)=>{ console.log(`errors:${error}`); }).then((res2)=>{ console.log(`userId:${res2.userInfo.userId}`) }).catch((error)=>{ }) Promise.all([checkLogin(),getUserInfo()]).then(([res1,res2])=>{ console.log(`result1:${res1.result},reult2:${res2.userInfo.userId}`); })