19, Penguin Magic


// the original Animal class and sayName method
function Animal(name, numLegs) {
    this.name = name;
    this.numLegs = numLegs;
Animal.prototype.sayName = function() {
    console.log("Hi my name is " + this.name);

// define a Penguin class
function Penguin(name) {
    this.name = name;
    this.numLegs = 2;

// set its prototype to be a new instance of Animal
Penguin.prototype = new Animal();
var penguin = new.Penguin("pingu");

i get a syntaxerror, unexpected identifier at line 20, it seems like I did everything fine though...


for a reason i don't understand you added a . between new and Penguin:

var penguin = new.Penguin("pingu");

why? it shouldn't be. You do it right the line above:

Penguin.prototype = new Animal();

a space after new, not a .


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.