箭头函数中的花括号 [英] Curly Brackets in Arrow Functions
本文介绍了箭头函数中的花括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以,请解释以下内容:
can someone, please explain the following:
我正在听丹·阿布拉莫夫 (Dan Abramov) 的讲座 &做练习.
I'm following Dan Abramov's lectures & doing the exercises.
代码工作正常,但是,当以下特定函数用大括号**{ }**
编写时,测试失败.
The code works fine, however, the tests fail when the following particular function is written with curly brackets **{ }**
.
case 'toggleTodo' :
return (
state.map( (one) => {
oneTodo( one, action )
})
);
相同的代码没有大括号就可以正常工作.
The same code works fine without curly brackets.
case 'toggleTodo' :
return (
state.map( (one) =>
oneTodo( one, action )
)
);
这里是 JsBin.请参阅第 31 行以后.
Here is the JsBin. Please refer to line 31 onwards.
推荐答案
case 'toggleTodo' :
return (
state.map( (one) =>
oneTodo( one, action )
)
);
等于:
case 'toggleTodo' :
return (
state.map( (one) => {
return oneTodo( one, action )
})
);
查看返回语句
这篇关于箭头函数中的花括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文