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 trialThomas Katalenas
11,033 Pointsplaylist instead of Playlist constructor? but why..
around the 7:10 to 7: 30 duration in the video
we can see the code uses
playlist.play
playlist.next
playlist.stop
yet in the playlist.js file it is clear to see that the constructor is Playlist with a capital P as seen below. is this referenceing the playlist.js file is that why it is lower case?
Playlist.prototype.play = function() {
var currentSong = this.songs[this.nowPlayingIndex];
currentSong.play();
};
Playlist.prototype.stop = function(){
this.stop();
this.nowPlayingIndex++;
if(this.nowPlayingIndex == this.songs.length){
this.nowPlayingIndex = 0;
};
this.play();
};
1 Answer
Jennifer Nordell
Treehouse TeacherNo. In app.js on the first line at the start of the video you have this line:
var playlist = new Playlist();
This creates a new instance of a Playlist object which will now be referenced to simply as playlist
. In reality, you could have named this any valid JavaScript variable name. For example, myPlaylist
or yourPlaylist
. Those would then be referenced by those names.
Hope this helps!