js中的导出语句

export statement in js

react's blog中有代码示例。 看起来像这样:

export class Counter extends React.Component {
  constructor(props) {
    super(props);
    this.state = {count: props.initialCount};
  }
  tick() {
    this.setState({count: this.state.count + 1});
  }
  render() {
    return (
      <div onClick={this.tick.bind(this)}>
        Clicks: {this.state.count}
      </div>
    );
  }
}

在这种情况下,export 语句是什么意思? 我找到了 this article on mdn 但它描述了另一个含义

用于ES6 modules

在这种情况下,它从该模块导出 class,因此您可以使用以下方法将其导入另一个模块:

import { Counter } from 'path_to_counter';

ES6 转译需要 Webpack to do the module loading if you are using a browser, and possibly a transpiler like Babel.js 之类的东西