0
有关向对象添加方法的快速问题。将方法添加到类原型中,错误
为什么我会收到错误? 我检查了语法,它似乎是正确的。 JavaScript新手。
// create your Animal class here
function Animal(name, numLegs) {
this.name = name;
this.numLegs = numLegs;
}
// create the sayName method for Animal
Animal.prototype.sayname = function() {
console.log("Hi my name is " + this.name);
};
// test
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();
我得到这个错误回到尝试运行的代码
TypeError: Object #<Animal> has no method 'sayName'