我可以用async关键字将JavaScript函数标记为“async”(即返回promise)。这样地:
async function foo() {
// Do something
}
箭头函数的等效语法是什么?
我可以用async关键字将JavaScript函数标记为“async”(即返回promise)。这样地:
async function foo() {
// Do something
}
箭头函数的等效语法是什么?
当前回答
对于静态异步箭头函数,其工作方式如下:
static myFunction = async () => {
// your code here
}
其他回答
对于静态异步箭头函数,其工作方式如下:
static myFunction = async () => {
// your code here
}
基本示例
folder = async () => {
let fold = await getFold();
//await localStorage.save('folder');
return fold;
};
带参数的异步箭头函数语法
const myFunction = async (a, b, c) => {
// Code here
}
立即调用异步箭头函数:
(async () => {
console.log(await asyncFunction());
})();
立即调用的异步函数表达式:
(async function () {
console.log(await asyncFunction());
})();
您还可以执行以下操作:
YourAsyncFunctionName = async (value) => {
/* Code goes here */
}