Inheriting and parameters - why the double up?


Hi all, I'm a little confused with the Emperor constructor, why do I need to write
in the parameter and
' = name;'
underneath, when the emperor inherits from animal (immediately below). Why doesn't it also inherit the name parameter? Why the double up?


function Penguin(name) { = name;
    this.numLegs = 2;

// create your Emperor class here and make it inherit from Penguin
function Emperor(//why do I need 'name' here?>){
//why do I need to repeat = name;?    

Emperor.prototype = new Penguin();

// create an "emperor" object and print the number of legs it has
var emperor = new Emperor("jessie");


How else are you going to give you emperor a name?

Inheritance is very useful for inheriting member variables and methods. But name is depended for each instance:

# emperor instance of Emperor object
var emperor = new Emperor("jessie");

so for instance variable, inheritance is not particular useful


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