function Dog(name,age,type){
this.name = name;
this.age = age;
this.type = type;
}
Dog.prototype = {
show : function(){
alert(this.name + "我是最快乐的狗狗");
}
}
function Teddy(name,age,type,color){
Dog.call(this,name,age,type)
this.color = color;
}
Teddy.prototype = new Dog();
var xiaohong = new Teddy("xiaohong","18","泰迪","红红色")
xiaohong.show();
alert(xiaohong.name)
上面代码中如果不要Teddy.prototype = new Dog();的话,
alert(xiaohong.name)这个的意思是不是Teddy继承了Dog的属性?
而加上Teddy.prototype = new Dog();的意思是不是
就是Teddy继承了Dog的方法?