Javascript使用class的静态属性

import React from 'react';

export default class ToolButton extends React.Component {
  static propTypes = {
    name: React.PropTypes.string
  };

  render () {
    return (
      <div></div>
    );
  }
}

上面的代码使用了 static propTypes, ES6原本不支持这种写法, 但是babel支持,需要使用"transform-class-properties"这个插件。

另外在使用eslint做校验的时候会报错‘Unexpected token’,原因是因为eslint本身不支持这种写法,需要使用babel-eslint。另外babel-eslint需要安装estraverse-fb。

posted @ 2016-03-11 17:13  Farmer.D  阅读(1270)  评论(0)    收藏  举报