【发布时间】:2017-11-08 14:26:51
【问题描述】:
我有这样的js递归fn
const recur = () => {
fetchSomething().then( res => {
if(typeof res.data == 'undefined'){ recur() }
else { console.log(res.data) }
})
}
recur()
我可以将上面的代码应用到 Async/Await 样式吗?
【问题讨论】:
-
您确定不想
return承诺和return recur()? -
这段代码现在可以在我的项目中正常使用了。我只需要将其更改为 async/await @Bergi 但将来我不确定
-
为什么你需要来改变它?
then在 ES8 中也可以正常工作。但是如果你想改进代码,我会说返回用于链接和错误处理目的的承诺比语法糖更重要 -
res.data === undefined -
感谢新知识的使用,而不是递归。还有
res.data === undefined@torazaburo
标签: javascript promise async-await ecmascript-next