// function timeout(ms) { // return new Promise((resolve) => { // setTimeout(resolve, ms); // }); // } // timeout 还是换一下写法 async function timeout(ms) { await new Promise((resolve) => { setTimeout(resolve, ms); }); } // async表示函数里有异步操作,await表示紧跟在后面的表达式需要等待结果。 async function asyncPrint(value, ms) { console.log('start run'); await timeout(ms); console.log(value, new Date()); await timeout(ms); console.log(value, new Date()); console.log("end"); } asyncPrint('hello world', 2000);