首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js继承的一些有关问题

2012-10-26 
js继承的一些问题//动物 function Animal(){this.species 动物 } //猫 function Cat(name,color){thi

js继承的一些问题

//动物 function Animal(){   this.species = "动物"; } //猫 function Cat(name,color){   this.name = name;   this.color = color; } 

?
如果采用prototype方式继承的话:

Cat.prototype = new Animal(); Cat.prototype.constructor = Cat; var cat1 = new Cat("大毛","黄色"); alert(cat1.species); // 动物 

?

?

____________________________________________________________________________________________________________________________________问题1:?Cat.prototype.constructor = Cat;为什么要重新指向?Cat.prototype.constructor 是否丢失?

?Cat.prototype.constructor 属性没有丢失,只是指向了Animal

?

问题2:是不是只有类才有prototype属性,类实例没有prototype属性?

var cat2=new Animal();

alert(cat2.prototype);//报错

热点排行
Bad Request.