課程
/前端開發
/JavaScript
/JavaScript深入淺出
為什么person是student的父類?
2017-08-25
源自:JavaScript深入淺出 1-5
正在回答
因為有一句
Student.prototype?=?new?Person()
郁悶的西海 提問者
es5中沒有類似extends這樣的關鍵字實現繼承。這個例子是基于原型鏈的繼承。
var stu = new Student();
stu.__proto__ = Student.prototype ,
Student.ptototype.__proto__ = ( new Person() ).__proto__ = Person.prototype ,?
stu.__proto__.__proto__ = Person.prototype
所以可以說 Student 繼承 Person , 即Person 為 Student 的父類。
我的理解。
舉報
由淺入深學習JS語言特性,且解析JS常見誤區,從入門到掌握
2 回答創建student的時候為什么不用new Person()
1 回答Student繼承Person后,它的prototype.constructor是Student吧?
5 回答為什么不是Student = Object.create(Person);和Student.prototype = Object.create(Person.prototype);有什么區別
2 回答Student和Student.prototype是什么關系圖中為什么只有Student.prototype沒有student
2 回答關于為什么是子類prototype指向父類prototype的問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-08-25
因為有一句
2017-08-25
es5中沒有類似extends這樣的關鍵字實現繼承。這個例子是基于原型鏈的繼承。
stu.__proto__ = Student.prototype ,
Student.ptototype.__proto__ = ( new Person() ).__proto__ = Person.prototype ,?
stu.__proto__.__proto__ = Person.prototype
所以可以說 Student 繼承 Person , 即Person 為 Student 的父類。
我的理解。