react 怎么区分是元素/实例?

var Father = React.createClass({
  componentDidMount:function(){
    var a = <Son /> ;
    console.log( this.refs.fff instanceof Son);
    console.log( React.isValidElement(a)) ;
    console.log( a instanceof Son) ;
    console.log( a.type === Son) ;
    console.log(this.refs.fff.show())
  },
  render : function() {
    return (<div>
      <h2 ref="titit">{this.props.title}</h2>
      <Son ref="fff"/>
    </div>)
  }
});

无法理解 a instanceof Son 是false 。
照说a 和 this.refs.fff 都应该是Son构造函数的实例啊?

阅读 2.6k
1 个回答

推荐看一下这个~ http://purplebamboo.github.io...

jsx编译成js的话,

var a = <Son />;

变成:

var a = React.createElement(Son, null);

看着也不像

var a = new Son();

之类的。
而且 React.createElement()返回的是一个ReactElement实例哦。

哎,好像我也解释不来(理解得不是很深)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进