xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

async function & no return await All In One

async function & no return await All In One

async function return await 错误的使用方式 ❌

image

image

image

ESLint no-return-await

/*eslint no-return-await: "error"*/

async function foo() {
    //  ESLint 检查 ✅
    return bar();
}

async function foo() {
    // 绕过 ESLint 检查 ❌
    await bar();
    return;
}

// This is essentially the same as `return await bar();`, but the rule checks only `await` in `return` statements
async function foo() {
    // 绕过 ESLint 检查 💩
    const x = await bar();
    return x;
}

// In this example the `await` is necessary to be able to catch errors thrown from `bar()`
async function foo() {
    try {
        // 只有需要使用 try...catch 捕捉错误的时候,才需要使用  return await 来获取错误信息 ✅
        return await bar();
    } catch (error) {}
}

https://eslint.org/docs/latest/rules/no-return-await

no return await

https://javascript.info/async-await

https://zh.javascript.info/async-await

https://github.com/javascript-tutorial/en.javascript.info/tree/master/1-js/11-async/08-async-await

PR

https://github.com/javascript-tutorial/en.javascript.info/pull/3343

https://github.com/xgqfrms/en.javascript.info/tree/patch-1

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

Learning JavaScript Async Await In Depth All In One / 深入学习 Async Await

https://www.cnblogs.com/xgqfrms/p/17074186.html

https://stackoverflow.com/questions/44806135/why-no-return-await-vs-const-x-await

https://juejin.cn/post/6934300573638328333

https://juejin.cn/post/6891547378231279623

https://github.com/davidlin88/blogs/issues/2



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-01-30 11:03  xgqfrms  阅读(59)  评论(0编辑  收藏  举报