JavaScript 箭头函数中的问题

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


SMILET
浏览 165回答 1
1回答

LEATH

箭头函数语法有点像这样(a) => b(a);is equivalent tofunction(a) {    return b(a);}但是,当您添加{}到箭头函数时,它会改变含义:(a) => { b(a); }is equivalent tofunction(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); }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript