我是新手我已经在此链接中下载了一些源 https://github.com/the-road-to-learn-react/react-redux-example 我在文件 src/app.js 第 4 行中有一些问题const applyFilter = searchTerm => article => article.title.toLowerCase().includes(searchTerm.toLowerCase());为什么这不能与const applyFilter = searchTerm => article =>{ article.title.toLowerCase().includes(searchTerm.toLowerCase());} 或者const applyFilter = searchTerm => {article => article.title.toLowerCase().includes(searchTerm.toLowerCase());}并在第 14 行调用函数时articles.filter(applyFilter(searchTerm))const applyFilter = searchTerm => article => article.title.toLowerCase().includes(searchTerm.toLowerCase());这在我看来是在箭头函数内调用箭头函数?他们怎么能把 var 'article' 放进去?
1 回答

LEATH
TA贡献1936条经验 获得超7个赞
箭头函数语法有点像这样
(a) => b(a);
is equivalent to
function(a) {
return b(a);
}
但是,当您添加{}到箭头函数时,它会改变含义:
(a) => { b(a); }
is equivalent to
function(a) {
b(a);
// notice that this doesn't actually return anything,
// it just calls a function and does nothing with the result
}
所以加括号的时候要加return语句
(a) => { return b(a); }
添加回答
举报
0/150
提交
取消