请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

pureComponent

pureComponentPrototype.constructor = PureComponent;
// Avoid an extra prototype jump for these methods.
Object.assign(pureComponentPrototype, Component.prototype);

这个地方没太理解,为什么要assign一下

正在回答 回答被采纳积分+3

2回答

DevinLin 2019-03-18 08:15:34

只是用来实现继承,这样写只是为了兼容性

0 回复 有任何疑惑可以回复我~
提问者 诺巴蒂 2019-03-07 13:52:26

还有一个问题:

ComponentDummy

这个是做啥用的,为啥不直接继承 Compoent , 为了去除 Compoent 里的方法吗

0 回复 有任何疑惑可以回复我~
  • Jokcy #1
    因为要把方法拷贝到pureComponentPrototype上。用ComponentDummy是为了不直接实例化一个Component实例,可以减少一些内存使用。建议你可以去了解一下JS中实现继承的方式。
    回复 有任何疑惑可以回复我~ 2019-03-07 18:26:51
  • 提问者 诺巴蒂 回复 Jokcy #2
    可是已经继承了 Component ,为啥还要将 Component 里 prototype 方法属性拷贝到 pureComponent 的 prototype 上
    回复 有任何疑惑可以回复我~ 2019-03-08 17:18:16
  • Jokcy 回复 提问者 诺巴蒂 #3
    代码上有一句注释:
    `// Avoid an extra prototype jump for these methods.`
    就是为了避免多一次原型链查找。
    回复 有任何疑惑可以回复我~ 2019-03-09 21:23:32
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号