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
Ryan Libed
7,386 PointsCan someone please explain what 'this' is actually referring to in Media.call(this, title, duration);?
Can someone please explain what 'this' is actually referring to in Media.call(this, title, duration);?
I've read all the questions and answers among the video in this thread and have looked elsewhere on the web and it still isn't clear. Can someone please break it down in a simpler way? Andrew's way of teaching is failing me once again....
2 Answers
Seth Kroger
56,416 Pointsthis in this instance is the Song (or Video) object being constructed. We are calling Media(title, duration) but also telling it that the this inside Media() should be the very same object that this is inside Song().
Ryan Libed
7,386 PointsThank you for the explanation!
Ryan Libed
7,386 PointsRyan Libed
7,386 PointsThank you.
However, why is Andrew removing this.isPlaying from the Song object constructor? I don't understand how the Song object constructor inherits this.isPlaying from the Media.call() if it's not used as one of the parameters?
Seth Kroger
56,416 PointsSeth Kroger
56,416 PointsThe object you create will have all the properties given to it by both Song() and Media(). Since
isPlayingis set in Media() to a default value of false, it doesn't need to passed in.