pureComponent

来源:2-4 react-component

诺巴蒂

2019-03-07

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

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

写回答

2回答

DevinLin

2019-03-18

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

0
0

诺巴蒂

提问者

2019-03-07

还有一个问题:

ComponentDummy

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

0
3
Jokcy
回复
诺巴蒂
代码上有一句注释: `// Avoid an extra prototype jump for these methods.` 就是为了避免多一次原型链查找。
2019-03-09
共3条回复

React源码深度解析 高级前端工程师必备技能

掌握React源码,让你的开发水平没有上限,更不惧前端未来的到来

1749 学习 · 336 问题

查看课程