關于為什么是子類prototype指向父類prototype的問題
求解 ?Student 的prototype為啥不直接指向Person,而要指向Person.prototype呢? 如: student-student.prototype --> person-person.prototype --> object-object.prototype --> null
求解 ?Student 的prototype為啥不直接指向Person,而要指向Person.prototype呢? 如: student-student.prototype --> person-person.prototype --> object-object.prototype --> null
2017-05-12
舉報
2019-02-21
首先Student.prototype 不會指向 Person.prototype;而是Student.prototype._proto_指向Person.prototype。也不存在直接指向 Person;他們之間的繼承是通過原型鏈,一一往上繼承使用的。這不是嚴格像Java那樣繼承,感覺是這樣繼承的形式,本質上還是有區別的。
2017-05-13
是用 new Student出來的實例student的_proto_指向Student.prototype,而Student.prototype又等于用Object.creat()創造出來的空對象,這個空對象的原型指向Person.prototype,從而Student.prototype可以使用Person.prototype上的方法。Person.prototype又是一個對象,所以Person.prototype._proto_又指向Object.prototype。個人理解,如有誤望大佬指正。