亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

javascript原型繼承問題,問題在下面代碼注釋里,麻煩大家了,謝謝

javascript原型繼承問題,問題在下面代碼注釋里,麻煩大家了,謝謝

yuqingzhijie3596863 2017-03-22 10:10:23
<script type="text/javascript">? ? ? ? ? ? ? ? ? ??? ? ? ? function SuperType(name){? ? ? ? ? ? this.name = name;? ? ? ? ? ? this.colors = ["red", "blue", "green"];? ? ? ? }? ? ? ??? ? ? ? SuperType.prototype.sayName = function(){? ? ? ? ? ? alert(this.name);? ? ? ? };? ? ? ? function SubType(name, age){ ?? ? ? ? ? ? SuperType.call(this, name);? ? ? ? ? ??? ? ? ? ? ? this.age = age;? ? ? ? }????????//---------------------------------問題在下一行------------------------------? ? ? ? //SubType.prototype = new SuperType();//這里我特意注釋掉,然后我覺得subtype實例應該不能調用sayAge和sayName方法了,但實際能正常調用sayAge,而不能掉用sayName,為什么??? ? ? ??? ? ? ? SubType.prototype.sayAge = function(){? ? ? ? ? ? alert(this.age);? ? ? ? };? ? ? ??? ? ? ? var instance1 = new SubType("Nicholas", 29);? ? ? ? instance1.colors.push("black");? ? ? ? alert(instance1.colors); ?//"red,blue,green,black"? ? ? ? //instance1.sayName(); ? ? ?//"Nicholas";? ? ? ? instance1.sayAge(); ? ? ? //29//調用sayAge正常運行,不會報錯? ? ? ? ??? ? ? ? var instance2 = new SubType("Greg", 27);? ? ? ? alert(instance2.colors); ?//"red,blue,green"? ? ? ? instance2.sayName(); ? ? ?//"Greg";//調用sayName會報錯? ? ? ? instance2.sayAge(); ? ? ? //27? ? ? ?? ? ? ??? ? </script>
查看完整描述

1 回答

  • 1 回答
  • 1 關注
  • 1009 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號