我正在学习继承。在下面的代码中
1)企鹅继承自Animal
2)当我打电话给 penguin.sayName(); 为什么会输出“嗨,我的名字未定义”;
function Animal(name,numLegs){
this.name = name;
this.numLegs = numLegs;
}
Animal.prototype.sayName = function(){
console.log("Hi my name is " + this.name);
};
function Penguin(){}
Penguin.prototype = new Animal();
var penguin = new Penguin("Captain Cook", 2);
penguin.sayName();