亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JavaScript 箭頭函數中的問題

JavaScript 箭頭函數中的問題

SMILET 2021-12-23 18:06:42
我是新手我已經在此鏈接中下載了一些源 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); }


查看完整回答
反對 回復 2021-12-23
  • 1 回答
  • 0 關注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號