Welcome to the Treehouse Community
Looking to learn something new?
Song.prototype = Object.create(Media.prototype) question
Song.prototype = Object.create(Media.prototype);
Andrew says, "This will copy the references to the media’s prototype properties and methods to the song’s prototype. This is to create the relationship between the two things right now."
Why do you need to copy these references from Media into Song? Based on the inheritance, can't Song just directly access the Media prototype methods?**
Seth Kroger56,407 Points
I like to think that ineritance will bring every element from the father
s constructor to the childs constructor. In this case, it will bring the Media attributes to the Song constructor. If you have any methods inside the constructor those methods will be available to the children as well. However, when you use prototypes to define methods they are not inside the constructor`s curly brackets, and for that reason you must create the association between parent and children using a different command, whic is the Object.create().
Andrew Dickens18,352 Points
Hi Seth and Andre, thanks for you explanations, still unsure why we need Song.prototype = Object.create(Media.prototype) ; Did we not do that with call()? What do you think of this statement?
Using call() is to share the properties and methods from one object constructor to another BUT you still need to set up a prototype chain for the js interpreter to read and link the object constructors together