codeacademy的代码片段中的错误是什么

Rtr*_*Rtr 0 javascript

当我运行以下代码时,我收到一个错误: TypeError: Object [object Object]

// create your Animal class here

function Animal(name, numLegs)
{
    this.name = name;
    this.numLegs = numLegs;
}

// create the sayName method for Animal

Animal.prototype = function sayName()
{
    console.log("Hi, my name is [name]");
};
// provided code to test above constructor and method
var penguin = new Animal("Captain Cook", 2);
penguin.sayName();
Run Code Online (Sandbox Code Playgroud)

为什么?

iCo*_*nor 5

我认为这是问题所在

   Animal.prototype = function sayName(){

     console.log("Hi, my name is [name]");

   };
Run Code Online (Sandbox Code Playgroud)

应该

   Animal.prototype.sayName = function(){

     console.log("Hi, my name is ", this.name);

   };
Run Code Online (Sandbox Code Playgroud)

另外[name]是不是JavaScript的:S

演示