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 trialclemhlrdt
20,534 PointsWhy do the function is called by itself here ?
In the playlist.js file, we create a constructor and define properties.
With prototype, we define Methods like this:
Playlist.prototype.play = function() { var currentSong = this.songs[this.nowPlayingIndex]; currentSong.play(); };
It is a bit confusing for me. I understand the role of prototype here BUT I don't understand the fact that we call the play function on the variable currentSong.
1 Answer
Katie Wood
19,141 PointsHello there,
In this project, 'Song' inherits from 'Media', which has a 'play' method. In media.js, we can see that the play method sets the 'isPlaying' property to 'true'. Then, back in song.js, we can see that the toHTML function checks for isPlaying. If it's true, it gives that song the class of 'current', which styles it differently. Basically, in this case, calling the 'play' method on the song indicates that it should be styled in a way that visually separates it from the other playlist items that are not considered to be playing at that time.
Hope this helps!
clemhlrdt
20,534 Pointsclemhlrdt
20,534 PointsThank you Katie Wood :) Love the shiba inu btw.
Katie Wood
19,141 PointsKatie Wood
19,141 PointsHaha, thank you! :)