react手册里说使用...传递,为什么浏览器提示错误

var FancyCheckbox = React.createClass({


  render: function() {


var { checked, ...other } = this.props;
var fancyClass = checked ? 'FancyChecked' : 'FancyUnchecked'; 
return (
      <div {...other} className={fancyClass} /> //***这里提示有错误***
    );
} 
});
React.render(
  <FancyCheckbox checked={true} onClick={console.log.bind(console)}>
    Hello world!
  </FancyCheckbox>,
  document.getElementById('example')
);

我用chome的console里看到如上提示有错误,手册...other为什么不能用

阅读 2.9k
3 个回答

... 是 ES6 新增的语法,要配合 babel 之类的预编译器编译为浏览器支持的语法(如 ES5)才能运行

var { checked, ...other } = this.props;

在这句下面console.log(...ohter),看有没有值。
这句话就不对吧。还有用es6 就不要用var 用let和const来声明变量

推荐问题