这题 es7 解法!
let sleep = [];
for (var i = 0; i < 5; i++) {
((j) => {
sleep.push(new Promise(function (resolve, reject) {
setTimeout(function () {
console.log(new Date, j);
resolve();
}, j * 1000)
}))
})(i)
}
// await只能使用在原生语法
(async () => {
for (let item of sleep) {
await item
}
console.log(new Date(), i);
})();