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

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构造函数的实例啊?


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

jsx编译成js的话,

var a = <Son />;

变成:

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

看着也不像

var a = new Son();

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

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

【热门文章】
【热门文章】