Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 高阶组件:函数关键字vs箭头函数_Javascript_Reactjs_Ecmascript 6_Higher Order Components - Fatal编程技术网

Javascript 高阶组件:函数关键字vs箭头函数

Javascript 高阶组件:函数关键字vs箭头函数,javascript,reactjs,ecmascript-6,higher-order-components,Javascript,Reactjs,Ecmascript 6,Higher Order Components,在演示如何创建高阶组件时,大多数示例都使用function关键字 React文档中的以下示例: function logProps(WrappedComponent) { return class extends React.Component { componentWillReceiveProps(nextProps) { console.log('Current props: ', this.props); console.log('Next props:

在演示如何创建高阶组件时,大多数示例都使用function关键字

React文档中的以下示例:

function logProps(WrappedComponent) {
  return class extends React.Component {
    componentWillReceiveProps(nextProps) {
      console.log('Current props: ', this.props);
      console.log('Next props: ', nextProps);
    }
    render() {
      // Wraps the input component in a container, without mutating it. Good!
      return <WrappedComponent {...this.props} />;
    }
  }
}

问题是:在function关键字中使用语法有什么区别吗?有什么好处吗?

在您的情况下没有区别-它们的行为相同

但在有些情况下情况并非如此——在这个话题上有一个很好的答案

export const collapse = (options) =>
(Trigger)  =>
   class C extends React.Component {
   }