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