Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Prototypal Inheritance Updating the Song Object

Matthew Day
Matthew Day
6,740 Points

Is the call method used only to access properties while prototype is primarily used to access other methods?

At around 0:30, Andrew adds Media.call(this, title, duration) to the Song constructor and then mentions that in "JavaScript, you can call any function programmatically using the call method." He continues by saying that the same parameters in Media must also be present in Song (e.g. title and duration).

At 2:20, he adds Song.prototype = Object.create(Media.prototype) to set up the prototype chain and explains that doing so "copies the references to the Media's prototype properties and methods to the song's prototype."

With this in mind, I have a few questions:

  1. Is Media.call(this, title, duration) dependent on having the prototype chain in place? In other words, if I only wanted to access the parameters in Media, can I do this without defining a prototype chain?

  2. Although Andrew states that Song.prototype = Object.create(Media.prototype) copies both "properties and methods", it seems likes its main purpose is to access methods and not properties. Is this assumption correct?

1 Answer

Steven Parker
Steven Parker
231,275 Points
  1. The .call method works on any function. You don't need to have established any prototypes.
  2. Copying methods may be the main purpose in that particular example, but it should not be assumed the main purpose for copying prototypes in general.