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) Constructor Functions and Prototypes Making the UI Work

Gabriel Ward
Gabriel Ward
20,222 Points

Defintion for .stop() and .play() in playlist.js

I'm confused about where the definition for .stop() and .play() in playlist.js come from. Do the come from the isPlaying = true/false; definition for .stop() and .play in songs.js? Any help is much appreciated.

Gabriel Ward
Gabriel Ward
20,222 Points

Hmm ok thanks Kim. I think I need to just continue through the course and not get too hung up on the .stop(0 and .play(0 in playlist.js for now.

2 Answers

Kim Still
Kim Still
7,355 Points

Essentially, yes they com from the isPlaying boolean. All they do at this point is create a visual change, in your UI since there's no backend involved. So depending on the state of the isPlaying boolean (which .stop() and .play() change), a song appears to be playing.

I hope that helps.

romankozak2
romankozak2
5,782 Points

I don't understand this, as well. Hopefully at MOD can chime in.

The .play() and .stop() in the Playlist.prototype.play function confuse me in the playlist.js file. Is he using the prototype method from the Song constructor function? If so, I thought only instances of a constructor function inherit the methods? How can a prototype method from the Playlist constructor function call a method from the Song constructor function without prototypal inheritance (I hope that makes sense)? Isn't the .play() and .stop() prototype methods from the Song constructor function in the scope of that particular constructor function, and not global and accessible in the scope of another constructor function? And it's also very confusing because the prototype function that currentSong.play() is being called in is also Playlist.prototype.play. I'm mixing the plays up.

Lastly, then, how does the .play() in the Playlist.prototype.play function know which .play() to choose? That may be answered more clearly if the part of my question above is answered. Thanks!