js for循环的同步代码
async function fn() { for(var i=0; i<5; i++) { await (function(){ return new Promise(function(res, rej){ setTimeout(function(){ console.log("res") res(); },2000) }) }()) console.log(i) } }; fn()
async function fn() {for(var i=0; i<5; i++) {await (function(){return new Promise(function(res, rej){setTimeout(function(){console.log("res")res();},2000)})}())console.log(i)}};
fn()
天道酬勤