对着网上的例子打的,但是不能获取继承对象的属性
function Animal(){
this.species = "动物";
}
function Cat(name,color){
this.name = name;
this.color = color;
}
function extend(Child, Parent) { var F = function(){};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.uber = Parent.prototype;
}
extend(Cat,Animal);
var cat1 = new Cat("大毛","黄色");
alert(cat1.species); //为什么是undefined ??? 书上却说可以得到属性“动物”
function Animal(){
this.species = "动物";
}
function Cat(name,color){
this.name = name;
this.color = color;
}
function extend(Child, Parent) { var F = function(){};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.uber = Parent.prototype;
}
extend(Cat,Animal);
var cat1 = new Cat("大毛","黄色");
alert(cat1.species); //为什么是undefined ??? 书上却说可以得到属性“动物”
}
function Cat(name,color){
this.name = name;
this.color = color;
}
function extend(Child, Parent) {
var F = function(){
Parent.call(this);
};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.uber = Parent.prototype;
}
extend(Cat,Animal);
var cat1 = new Cat("大毛","黄色");
alert(cat1.species); //为什么是undefined ??? 书上却说可以得到属性“动物”
function Cat(name,color){
this.name = name;
this.color = color;
Animal.call(this)
}