在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/C++  HTML/ a=>b => c這種函數(shù)如何理解

a=>b => c這種函數(shù)如何理解

es6中高階函數(shù)多個(gè)箭頭函數(shù)級(jí)聯(lián)的情況如何很好的理解代碼

const setTitle = (title) => (WrappedComponent) => {
   return class extends React.Component {
      componentDidMount() {
          document.title = title
      }
      render() {
         return <WrappedComponent {...this.props} />
      }
   }
}

PS追問(wèn)一下:大家說(shuō)的,我能夠理解了,但是每次都要在頭腦中做轉(zhuǎn)換,感覺(jué)代碼可讀性也不是特別的好,也可能是我太菜了。還有這種寫(xiě)法是不是最多也就寫(xiě)兩層。

回答
編輯回答
浪婳
2017年8月25日 15:08
編輯回答
魚(yú)梓

其實(shí)就是ES6的柯里化寫(xiě)法,也就是先定義一個(gè)函數(shù),然后再其內(nèi)再返回一個(gè)新的函數(shù)以接受第二個(gè)參數(shù)
補(bǔ)充:
可以不只是兩層。

2018年6月18日 19:37
編輯回答
紓惘

可以參考下js箭頭函數(shù)的幾種寫(xiě)法http://www.aazzp.com/2017/11/...

2017年12月8日 07:15
編輯回答
晚風(fēng)眠
const setTitle = (title) => (WrappedComponent) => {}
//格式上可以看做
const setTitle = function(title){
    return function(WrappedComponent){
       
    }
}
2018年7月15日 09:22
編輯回答
朕略傻
const setTitle = (title) => {
return (WrappedComponent) => {
   return class extends React.Component {
      componentDidMount() {
          document.title = title
      }
      render() {
         return <WrappedComponent {...this.props} />
      }
   }
 }
}

從右往左,相當(dāng)于(title) => {return ()=>{}}

2017年1月8日 14:42