JavaScript 箭头函数中的问题

Problems In JavaScript Arrow Function

我是新手 我已经在此 link 下载了一些源代码 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' 放进去??

箭头函数语法有点像这样

(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); }