如果对象包含'four',在所有其他情况下为false
,我如何从promise中获得真正的决心P.S。对不起我的英文
let asyncForEach = function(object, callback) {
let p = Promise.resolve();
for (const item of object) {
p = p.then(() => item).then(callback);
}
return p;
}
let asyncRequest = value => new Promise(resolve =>
setTimeout(resolve(value), 150));
let object = ['one', 'two', 'three', 'four', 'five'];
let result = asyncForEach(object, asyncRequest);
result.then(resolve => document.getElementById('result').innerHTML = resolve)
<div id="result"></div>