日期:2014-05-16 浏览次数:20420 次
//动物
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);//报错