困惑的点找到了
Topic source[https://www.bilibili.com/video/BV1J54y1y7u9/?spm_id_from=333.337.search-card.all.click&vd_source=ad4a82ae98755f9c9297acc0d10e7d95](https://www.bilibili.com/video/BV1J54y1y7u9/?spm_id_from=333.337.search-card.all.click&vd_source=ad4a82ae98755f9c9297acc0d10e7d95)
这篇归纳总结的很好。。。。算大概搞懂为啥了链接文字
我自己的方法,子类实例化的时候,子类的prototype属性会多一份父类的实例属性和方法,父类当中的prototype不会有两份,这个是共享的
非常建议大家自己敲一遍在浏览器看看实例化后的对比,可以看下以下的区别
-
PrimaryStudent {name: '孙墨泽', grade: 1, hello: ƒ}
-
grade: 1
-
hello: ƒ ()
-
name: "孙墨泽"
-
[[Prototype]]: Student
-
constructor: ƒ PrimaryStudent(props)
-
hello: ƒ ()
-
name: undefined
-
[[Prototype]]: Object
-
PrimaryStudent {name: '孙墨泽', grade: 1, hello: ƒ}
-
grade: 1
-
hello: ƒ ()
-
name: "孙墨泽"
-
[[Prototype]]: Student
-
consturctor: ƒ PrimaryStudent(props)
-
[[Prototype]]: Object
- 1
Up.
廖老师的代码一直觉得怪怪的,和上面这段代码比起来空函数F有点多余,这样也能同样保证原型链呀?有没有人能解答下