You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 来自高级前端面试,我选错了asyncfunctiongetData(){returnawaitPromise.resolve('I made it!');}constdata=getData();console.log(data);// 选CA."I made it!"B.Promise{<resolved>: "I made it!"}C.Promise{<pending>}D.undefined// 如果再加上下面这段代码setTimeout(()=>console.log(data),1000)// 那么会输出我想要的答案:Promise{<resolved>: "I made it!"}// 不加 setTimeout 该如何修改呢?constdata=awaitgetData();console.log(data);// Promise {<resolved>: "I made it!"}
异步函数定义
BoundNames
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
« "*default*" »
实例化函数对象
伴有参数 scope。
AsyncFunctionDeclaration : async function BindingIdentifier ( 形参 ) { AsyncFunctionBody }
AsyncFunctionDeclaration : async function ( 形参 ) { AsyncFunctionBody }
EvaluateBody
伴有参数 functionObject 和 List argumentsList。
AsyncFunctionBody : FunctionBody
求值
AsyncFunctionDeclaration : async function BindingIdentifier ( FormalParameters ) { AsyncFunctionBody }
AsyncFunctionDeclaration : async function ( FormalParameters ) { AsyncFunctionBody }
AsyncFunctionExpression : async function ( FormalParameters ) { AsyncFunctionBody }
AsyncFunctionExpression : async function BindingIdentifier( FormalParameters ) { AsyncFunctionBody }
AwaitExpression : await 一元表达式
2020-03-18 补充
2020-07-18 补充
前两天在对接苏宁联盟淘客API时遇到了小问题,记录下。
我调了它的推荐商品api,期望能拿到商品下的优惠券信息,包括以领取情况,令人失望的是,这个接口没给出,需要我拿到券URL再去调 https://open.suning.com/ospos/apipage/toApiMethodDetailMenuNew.do?interCode=suning.netalliance.couponinfo.query 这个接口才能得到券领用情况。
这样我就不得不再商品列表接口返回时遍历再去调用接口,直接用下面代码返回的
list
是由空对象组成的数组,很明显不对:后来我用了
for await of
才将其解决!这个问题本质是异步函数内调用接口等待返回数据后,再对返回数据进行遍历,遍历过程中还需要去调接口拿数据,即异步套异步,单纯在
map
里面加async
并不能立即拿到数据2020-07-25 补充
Daily-Interview-Question——第 160 题
The text was updated successfully, but these errors were encountered: