How to set prototype property


#1

My penguin behaves correctly - but I want to ask about how to set object properties from parameters:

Following he DRY principle I want to remove the line "this.name= name;"
in the Emperor constructor,
function Emperor(name) {
** this.name= name;**
}

And instead have the constructor from the prototype invoked, something like: super(name);

I came back to CodeAcademy, where I learnt Javascript, to see if I had forgotten how to do this. Re-doing the course I became aware the course spells out clearly that object properties set from parameters have to be set in the object constructor, and not in the prototype. Property inheritance is only demonstrated for properties set in the prototype.

I would welcome more emphasis about this, and discussion how to minimize the amount of code written when there are a lot of different objects with settable properties that inherit from a common prototype. The discussions in Stack Overflow are complicated and confusing.


Replace this line with your code.


#2

I believe these two articles are where you'll want to start


#3

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