javascript - 尝试定义异步函数

标签 javascript function asynchronous

我正在尝试使用箭头函数定义异步函数。这段代码已经抛出了一个错误,但我仍然想知道主要错误是什么。

async responseName = name => ('hello'+ name);  
responseName('joshua').then(response => console.log(response));

最佳答案

您有语法错误。您不能将标识符定义为异步:

const responseName = async (name) => `hello ${name}`;

关于javascript - 尝试定义异步函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54131089/

相关文章:

javascript - 获取 JSON 中的最后一个元素不起作用

javascript - 带有 className 的可拖动 div

javascript - 如何动态添加和删除grid的action列中的cls

php - 如何使 "PHPmailer"在函数中工作

.NET 异步套接字 : any benefit of SocketAsyncEventArgs over Begin/End in this scenario?

javascript - 将 div 放在 Master Slider 的顶部

javascript - React js如何返回带有异步超时的div

javascript - jQuery 将参数传递给 .ajax()

点击函数中的Javascript数组长度

java - Flushable.flush() 的一般行为是阻塞直到操作完成吗?