嗨,我想在async await没有任何回调包装器的情况下使用.then(function(){});要么something(anyparams,function(){});换句话说,我想通过将 promise 转换为来逐行使用我的代码async await问题:我已成功转换promise为async await 如果块出错,如何解决。预期输出是“结果:FFF”这是我的代码:function getName () { return new Promise(function (resolve, rejected) { var name = "FFF"; // wait 3000 milliseconds before calling resolve setTimeout ( function() { resolve( name ) }, 3000) })}async function foo () { console.log('Before Name'); var name = await getName(); console.log('After Name'); return name;}var str = foo();if(str == 'FFF'){ alert('result: '+str);}else{ alert('entered wrong block');}
添加回答
举报
0/150
提交
取消