采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
pureComponentPrototype.constructor = PureComponent; // Avoid an extra prototype jump for these methods. Object.assign(pureComponentPrototype, Component.prototype);
这个地方没太理解,为什么要assign一下
只是用来实现继承,这样写只是为了兼容性
还有一个问题:
ComponentDummy
这个是做啥用的,为啥不直接继承 Compoent , 为了去除 Compoent 里的方法吗
因为要把方法拷贝到pureComponentPrototype上。用ComponentDummy是为了不直接实例化一个Component实例,可以减少一些内存使用。建议你可以去了解一下JS中实现继承的方式。
可是已经继承了 Component ,为啥还要将 Component 里 prototype 方法属性拷贝到 pureComponent 的 prototype 上
代码上有一句注释: `// Avoid an extra prototype jump for these methods.` 就是为了避免多一次原型链查找。
登录后可查看更多问答,登录/注册
掌握React源码,让你的开发水平没有上限,更不惧前端未来的到来
1.8k 8
1.5k 7
1.3k 6
1.5k 6
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号