标签:st3 ons new pre dem set ++ blog return
let query; query = (url) => { return new Promise((resolve,reject) => { setTimeout(() => { console.log(url); if(true){ resolve(url); }else{ reject(); } }, 1000) }).catch((error)=>{console.log(error)}); }; query("test1") .then(query("test2")) .then(query("test3")) let arrCreate=()=>{ let arr=[]; for(let i=1;i<11;i++){ arr.push(query("test"+i)); } return arr; } let arr=arrCreate(); Promise.all(arr) .then(()=>{console.log("promise 全部执行了")}) .catch(function(error){console.log(error)});
以上是javascript中promise的链式操作demo
标签:st3 ons new pre dem set ++ blog return
原文地址:http://www.cnblogs.com/windseek/p/7650989.html