首页 > 代码库 > 玩转codecademy (二)

玩转codecademy (二)

 1 // create your Animal class here
 2 function Animal(name,numLegs){
 3     this.name=name,
 4     this.numLegs=numLegs
 5     }
 6 // create the sayName method for Animal
 7 Animal.prototype.sayName=function(){
 8     console.log("Hi my name is"+" "+prototype.name);
 9     }
10 
11 // provided code to test above constructor and method
12 var penguin = new Animal("Captain Cook", 2);
13 penguin.sayName();
View Code