課程
/前端開發(fā)
/JavaScript
/JavaScript深入淺出
為什么person是student的父類?
2017-08-25
源自:JavaScript深入淺出 1-5
正在回答
因?yàn)橛幸痪?/p>
Student.prototype?=?new?Person()
郁悶的西海 提問者
es5中沒有類似extends這樣的關(guān)鍵字實(shí)現(xiàn)繼承。這個(gè)例子是基于原型鏈的繼承。
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 的父類。
我的理解。
舉報(bào)
由淺入深學(xué)習(xí)JS語言特性,且解析JS常見誤區(qū),從入門到掌握
2 回答創(chuàng)建student的時(shí)候?yàn)槭裁床挥胣ew 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號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-08-25
因?yàn)橛幸痪?/p>
2017-08-25
es5中沒有類似extends這樣的關(guān)鍵字實(shí)現(xiàn)繼承。這個(gè)例子是基于原型鏈的繼承。
stu.__proto__ = Student.prototype ,
Student.ptototype.__proto__ = ( new Person() ).__proto__ = Person.prototype ,?
stu.__proto__.__proto__ = Person.prototype
所以可以說 Student 繼承 Person , 即Person 為 Student 的父類。
我的理解。