Nicely said. You also scratch the surface of the issue with inheritance: it become complex to find "who knows what" (and decrease performance). That's why, most of the time, composition is preferred above inheritance.
When someone's born, all her ancestor gather to teach her everything they knows. This way, she don't need to rely on her father (and his father, and his father ...).
Despite its complexity, probably one of the biggest advantages you get from prototypal inheritance is the fact that all properties and methods in the prototype chain refer to the same instance of said property or method.
This makes prototypal inheritance quite space-efficient because it does not need to duplicate properties and methods for every instance of a class. The instantiated object simply has to refer, or rather point, to the corresponding property or method in the prototype chain it lacks implementation for.
Oh, I just wanted to mention a "feature" that comes with prototypal inheritance for the sake of discussion since this post is about prototypal inheritance in the first place.
Also, I never actually thought of composition that way. I didn't know that the two objects would end up referencing the same speak method. That's pretty cool. Thanks for the heads up!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nicely said. You also scratch the surface of the issue with inheritance: it become complex to find "who knows what" (and decrease performance). That's why, most of the time, composition is preferred above inheritance.
When someone's born, all her ancestor gather to teach her everything they knows. This way, she don't need to rely on her father (and his father, and his father ...).
Despite its complexity, probably one of the biggest advantages you get from prototypal inheritance is the fact that all properties and methods in the prototype chain refer to the same instance of said property or method.
This makes prototypal inheritance quite space-efficient because it does not need to duplicate properties and methods for every instance of a class. The instantiated object simply has to refer, or rather point, to the corresponding property or method in the prototype chain it lacks implementation for.
We're getting off tracks here, but composition don't duplicate anything. Try this:
Oh, I just wanted to mention a "feature" that comes with prototypal inheritance for the sake of discussion since this post is about prototypal inheritance in the first place.
Also, I never actually thought of composition that way. I didn't know that the two objects would end up referencing the same
speak
method. That's pretty cool. Thanks for the heads up!