var listOfItems = [1, 2, 3, 4, 5];
listOfItems.forEach(
item => {
this.createTimeout(3000)
.then(
() => {
console.log(item);
})
});
createTimeout(timeout) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(null),timeout)
}) }
我想等待Promise回复' createTimeout'然后转到下一个元素。有什么想法吗?