如何在箭头函数中添加多个参数[重复]
Posted
技术标签:
【中文标题】如何在箭头函数中添加多个参数[重复]【英文标题】:How to add multiple parameters in arrow function [duplicate] 【发布时间】:2021-06-09 21:13:39 【问题描述】:已经为我的愚蠢问题感到抱歉,但谷歌搜索没有成功
如何在箭头函数中添加多个参数。我想在下面的函数中添加一些属性“props”。
const changeLocationHandler = async event =>
try
let hasError = false;
let response = await fetch('http://localhost:5000/api/game/location',
method: 'POST',
headers:
Authorization: 'Bearer ' + auth.token
,
body:
);
const responseData = await response.json();
if (!response.ok)
hasError = true;
if (hasError)
alert(responseData.message);
catch (error)
alert(error)
它不接受类似的东西
const changeLocationHandler = async event props =>
或
const changeLocationHandler = props => async event =>
提前致谢
【问题讨论】:
(event, props) => ...
javascript.info/arrow-functions-basics
只有1个参数的函数可以缺少()
这样的问题通常由谷歌搜索回答,如“mdn 箭头函数”
对不起,问这个问题的人 - 正如我所说的那样,这将是一个愚蠢的问题,是的,我看到了 mdn 网页但不明白它。无论如何感谢您的回答,它现在可以工作了。
【参考方案1】:
您需要将参数括在括号中才能正常工作。
const changeLocationHandler = async (event, arg2, arg3) =>
【讨论】:
以上是关于如何在箭头函数中添加多个参数[重复]的主要内容,如果未能解决你的问题,请参考以下文章
js中箭头函数 及 针对箭头函数this指向问题引出的单体模式