第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

prototype的問題

?function Animal(name) {?

? ? this.name = name;

?}?

?Animal.prototype = {

? ? weight: 0,?

? ? eat: function() {?

? ? ? ? alert( "Animal is eating!" );?

? ? }?

?}


?function Mammal() {?

? ? this.name = "mammal";?

?}?

?Mammal.prototype = new Animal("animal");?

?function Horse( height, weight ) {?

? ? this.name = "horse";?

? ? this.height = height;?

? ? this.weight = weight;?

?}

?Horse.prototype = new Mammal();?

?Horse.prototype.eat = function() {?

? ? alert( "Horse is eating grass!" );?

?}

?var horse = new Horse( 100, 300 );?

問題:

  1. Horse.prototype===?為true

  2. Mammal.prototype===?為true

  3. Animal.prototype===?為true

正在回答

2 回答

答案是:

Horse.prototype===horse.__proto__

Mammal.prototype===Horse.prototype.__proto__

Animal.prototype===Mammal.prototype.__proto__

本來(lái)我問問題的疑惑是 不清楚prototype ,proto和constructor它們的作用和意義

上面例子Animal,Mammal,Horse的prototype都被重寫了,Animal.prototype.constructor!==Animal ,Mammal和Horse也是一樣,__proto__就是[[proto]]也就是對(duì)象的指針,這個(gè)對(duì)象指針指向自己構(gòu)造函數(shù)的prototype.

1 回復(fù) 有任何疑惑可以回復(fù)我~

你的問號(hào)是什么意思


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
JavaScript深入淺出
  • 參與學(xué)習(xí)       281098    人
  • 解答問題       1048    個(gè)

由淺入深學(xué)習(xí)JS語(yǔ)言特性,且解析JS常見誤區(qū),從入門到掌握

進(jìn)入課程

prototype的問題

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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