I have a hard time understanding why I should define properties on the constructor class or its prototype object.
Here what i understand about prototype - declaring properties in prototypes (instead of the linked parent object) saves performance since each child object will not have its own COPY of the parent's properties.
Question: But I thought you can't copy values from non-primitive types i.e. function objects only pass references... and can only copy from primitives?
**Does this mean if I inherit parent's methods like below I am copying the reference to the methods or actually copies? **
function Parent() {
this.name = "jeff";
}
var child = new Parent();
console.log(child.name); /// is copied from parent or the reference is copied??
In the following example, I am referencing the prototype... right?
Parent.prototype.age = 9;
child.age // I looks at the parent class, then reference to prototype.age.
****Question 2:** If i can change the prototype.age for a particular object, then I'm actually copied the value right? So what's the point i.e.**
child.age = 10; // changed the value for THIS object