function Parent(firstName,color){ this.firstName = firstName; this.color = color; this.showName = function (){ console.log("我家姓氏:"+this.firstName); }}Parent.prototype.showAll=function(){ console.log("姓:"+this.firstName+"\n"+"喜愛的顏色:"+this.color);}function Child(myName,age,firstName,color){ this.myName = myName; this.age = age; Child.prototype=Parent.prototype; Parent.call(this,firstName,color);}/*Child.prototype=Parent.prototype;*/var c = new Child("帥",23,"孫","粉色");var d=new Parent("孫","粉色");d.showAll();//姓:孫 //喜愛的顏色:粉色c.showAll();//error c.showAll is not a functioncall對象冒充為什么this不能獲得構造函數Parent的原型?還有Child.prototype=Parent.prototype;寫在Child函數里不行,為什么拿出來寫在window環境就可以?
求高手回答原型繼承的問題
眼眸繁星
2018-11-13 17:19:57