async await的使用
var sleep = function (time) { return new Promise(function (resolve, reject) { setTimeout(function () { //此处执行异步操作 resolve('ok'); }, time); }); }; var start = async function () { try{ console.log('start'); var result = await sleep(1000); console.log(result); console.log('end'); }catch(err){ console.log(err); } }; start();