绑定类函数与util函数

时间:2017-01-13 09:29:57

标签: javascript function reactjs bind

我一直想知道宣布纯函数会更好。如果将它们声明为util函数则存在缺陷。所以:

import React, {Component, PropTypes} from 'react';

export const exampleFunction = () => {

};

class ExampleComp extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    const useExampleFunction = exampleFunction();
    return (
      <div></div>
    );
  }
}

ExampleComp.propTypes = {};

export default ExampleComp;

VS

import React, {Component, PropTypes} from 'react';


class ExampleComp extends Component {
  constructor(props) {
    super(props);
    this.exampleFunction = this.exampleFunction.bind(this);
  }

  exampleFunction() {

  }

  render() {
    const useExampleFunction = this.exampleFunction();
    return (
      <div></div>
    );
  }
}

ExampleComp.propTypes = {};

export default ExampleComp;

另外,如果我们将此函数声明为ExampleComp类的静态方法,那么将函数导出为静态类属性会更好吗?

0 个答案:

没有答案