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

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

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

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

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

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

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

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

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

2017年12月8日 07:15
編輯回答
晚風眠
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} />
      }
   }
 }
}

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

2017年1月8日 14:42