ES6本质
来源:3-5 添加交互行为

纯情掉了一地
2019-10-04
extends Component
组件都继承父组件 Component
this.state 也就是 Component.prototype.state 对吗?
写回答
1回答
-
你这样理解是不对的。如果this.state 是 Component.prototype.state,那么所有组件都会共享这个state,显然是不对的。可以这样理解,state是Component的一个实例属性,这样extends Component后,每一个具体的组件都会有state属性:
function Component(props) {
this.state = {};
//...
}
032019-10-10
相似问题