課程
/前端開發(fā)
/JavaScript
/JavaScript深入淺出
同樣的Person和Person.prototype什么關(guān)系,Person應(yīng)該在圖中的什么位置
2016-05-18
源自:JavaScript深入淺出 8-2
正在回答
Person.prototype.constructor指向Person。
實(shí)例查找屬性或方法會(huì)先從構(gòu)造函數(shù)開始查,所以如果Person有一個(gè)name屬性且Person.prototype也有一個(gè)name屬性,通過實(shí)例.name返回的是Person上的name屬性
function a(){this.name="aaa"}
//undefined
a.prototype.name="ccc"
//"ccc"
var b=new a()
b.name
//"aaa"
a.prototype.name
student.prototype ? 可以理解成是student的本體
舉報(bào)
由淺入深學(xué)習(xí)JS語(yǔ)言特性,且解析JS常見誤區(qū),從入門到掌握
5 回答為什么不是Student = Object.create(Person);和Student.prototype = Object.create(Person.prototype);有什么區(qū)別
1 回答關(guān)于Student.prototype的修改
4 回答Student.prototype.constructor = Student是什么意思?。?/p>
2 回答Student.prototype = Object.create(Person.prototype); Student.prototype.constructor = Person
2 回答請(qǐng)問為什么我輸入Student.prototype=new Person() 輸出的是 Object {}
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-09-16
Person.prototype.constructor指向Person。
實(shí)例查找屬性或方法會(huì)先從構(gòu)造函數(shù)開始查,所以如果Person有一個(gè)name屬性且Person.prototype也有一個(gè)name屬性,通過實(shí)例.name返回的是Person上的name屬性
function a(){this.name="aaa"}
//undefined
a.prototype.name="ccc"
//"ccc"
var b=new a()
//undefined
b.name
//"aaa"
a.prototype.name
//"ccc"
2016-05-18
student.prototype ? 可以理解成是student的本體