箭头功能中的卷曲支架 [英] Curly Brackets in Arrow Functions
本文介绍了箭头功能中的卷曲支架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我跟随丹·阿布拉莫夫的讲座和做练习
代码工作正常,但是当以下特定功能用大括号 **时,测试失败{} **
。
case'toggleTodo':
return(
state.map((one)=> {
oneTodo(one,action)
})
);
相同的代码工作正常,没有大括号。
case'toggleTodo':
return(
state.map((one)=>
oneTodo一个动作)
)
);
这是JsBin 。请参阅第31行。
解决方案
case'toggleTodo':
return(
state.map((one)=>
oneTodo(one,action)
)
);
等于:
case'toggleTodo':
return(
state.map((one)=> {
return oneTodo(one,action)
})
);
查看return语句
Would someone please explain the following:
Im following Dan Abramov's lectures & doing the exercises.
The code works fine, however the tests are failed 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 )
)
);
Here is the JsBin. Please refer to line 31 onwards.
解决方案
case 'toggleTodo' :
return (
state.map( (one) =>
oneTodo( one, action )
)
);
is equal to:
case 'toggleTodo' :
return (
state.map( (one) => {
return oneTodo( one, action )
})
);
see the return statement
这篇关于箭头功能中的卷曲支架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文