$(document).ready(initPage);
function initPage() {
extend2(Cat,Animal);
var cat1 = new Cat("大毛","黄色");
alert(cat1.species); // 动物
alert(cat1.name);
}
function extend2(Child, Parent) {
var p = Parent.prototype;
var c = Child.prototype;
for (var i in p) {
c[i] = p[i];
}
c.uber = p;
}
function Animal(){
}
Animal.prototype.species = "猫科1212433动物";
function Cat(name,color){
this.name = name;
this.color = color;
}
extend2
这个函数的作用,就是将父对象的prototype对象中的属性,一一拷贝给Child对象的prototype对象。