最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

js prototype的問題

js prototype的問題

慕粉3900206 2016-10-14 16:40:17
原文:當(dāng)時(shí)當(dāng)我們重新定義函數(shù)的prototype時(shí)(注意:和上例的區(qū)別,這里不是修改而是覆蓋), constructor的行為就有點(diǎn)奇怪了,如下示例:function?Person(name)?{ ????????????this.name?=?name; ????????}; ????????Person.prototype?=?{ ????????????getName:?function()?{ ????????????????return?this.name; ????????????} ????????}; ????????var?p?=?new?Person("haorooms"); ????????console.log(p.constructor?===?Person);??//?false ????????console.log(Person.prototype.constructor?===?Person);?//?false ????????console.log(p.constructor.prototype.constructor?===?Person);?//?false為什么呢? 原來是因?yàn)楦采wPerson.prototype時(shí),等價(jià)于進(jìn)行如下代碼操作:Person.prototype?=?new?Object({ ????????????getName:?function()?{ ????????????????return?this.name; ????????????} ????????});-------------------------------------------------------------分割線----------------------------------------------------問題1.為什么重新定義prototype后p.constructor?===?Person都會(huì)返回false問題2.Person.prototype?=?new?Object({ ????????????getName:?function()?{ ????????????????return?this.name; ????????????} ????????});沒看懂什么意思,為什么要在寫參數(shù)的位置定義屬性方法呢
查看完整描述

1 回答

  • 1 回答
  • 1 關(guān)注
  • 1223 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)