Why in Parasitic Combination Inheritance do you need to copy the prototype?
inheritance, javascript
Solution
In your method you are just aliasing a reference to the parent prototype. So whenever you add a method to the "child prototype" it actually just adds that to parent prototype.
And the first way doesn't copy the parent prototype, any methods added later to parent prototype are inherited, it's not a snapshot/copy.
Problem
In Professional JavaScript for Web Developers book there is a technique called Parasitic Combination Inheritance. I don't understand why do you need to get a clone of the original prototype, why don't you just set the SubType prototype to the prototype of the parent (SuperType). ``` function object(o){ function F(){} F.prototype = o; return new F(); } function inheritPrototype(subType, superType){ var prototype = object(superType.prototype); //create object -- why this is needed? prototype.constructor = subType; //augment object subType.prototype = prototype; //assign object } function SuperType(name){ this.name = name; this.colors = ["red", "blue", "green"]; } SuperType.prototype.sayName = function(){ alert(this.name); }; function SubType(name, age){ SuperType.call(this, name); this.age = age; } inheritPrototype(SubType, SuperType); SubType.prototype.sayAge = function(){ alert(this.age); }; ``` I tried changing it like this and it worked: ``` function inheritPrototype(subType, superType){ var prototype = superType.prototype; prototype.constructor = subType; //augment object subType.prototype = prototype; //assign object } ```