-
开心每一天1111
function app (num, data) { return new Promise(function (resolve, reject) { resolve(num) })}let data = [1, 2, 3]let res = Promise.resolve()for (let index = 0; index < data.length; index++) { res = res.then(v => { console.log(v) return app(index) })}
-
郎朗坤
如果你每次执行app()互相没有联系 可以放在一个数组里 用Promise.all来执行let p =[]for(let i=0;i<data.length;i++){ p.push(app(i,data))}Promise.all(p).then(res=>{ console.log(res)})
-
qq_花开花谢_0
function app(num, data) { return new Promise(function (resolve, reject) { resolve(num) })}function test(arr, cb) { return arr.reduce((p, v) => p.then(() => cb(v)), Promise.resolve())}test([4, 1, 9], function (num) { return app(num).then(res => { console.log(res) });})