为什么这里说“动物”而不是“小猫”?
// create base class Animal
function Animal(animalType) {
this.type = animalType;
this.sayType = function () {
alert(this.type);
};
}
// create derived class Cat
function Cat(myName) {
Animal.call(this, "cat"); // cat calls the Animal base class constructor
this.name = myName;
this.sayName = function () {
alert(this.name);
};
}
Cat.prototype = Object.create(Animal); // set Cat's prototype to Animal
// instantiate a new instance of Cat
var cat = new Cat("kitty");
cat.sayName();
cat.name = "lol";
cat.sayName();