關(guān)于為什么是子類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
舉報(bào)
2019-02-21
首先Student.prototype 不會指向 Person.prototype;而是Student.prototype._proto_指向Person.prototype。也不存在直接指向 Person;他們之間的繼承是通過原型鏈,一一往上繼承使用的。這不是嚴(yán)格像Java那樣繼承,感覺是這樣繼承的形式,本質(zhì)上還是有區(qū)別的。
2017-05-13
是用 new Student出來的實(shí)例student的_proto_指向Student.prototype,而Student.prototype又等于用Object.creat()創(chuàng)造出來的空對象,這個(gè)空對象的原型指向Person.prototype,從而Student.prototype可以使用Person.prototype上的方法。Person.prototype又是一個(gè)對象,所以Person.prototype._proto_又指向Object.prototype。個(gè)人理解,如有誤望大佬指正。