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 Playlist Project

What is the function of song.js and playlist.js?

I'm not sure what I'm trying to do in each sheet, what is the purpose of them?

2 Answers

Hey Wilfredo Casas ,

We have two constructor functions i.e. songs and playlist and both having their properties and methods.

In songs constructor function we're going to store information of songs and the methods like play,stop and toHTML and In playlist constructor function we're going to add the song instance in an array songs (which means we can access all the properties and methods of song constructor function from playlist object) and than we have several methods of playlist like add, next , previous and stop and we're going to do all stuffs in playlist methods using the song index. In app.js we will create instance of songs and passed all songs information in it and stored the instance of song in a variable. And In last we pass variable which holding song instance in instance of our playlist function.

I don't get one part, what's the moment where this happens? "(which means we can access all the properties and methods of song constructor function from playlist object)

var playlist  = new playlist(); //instance of playlist constructor function

var herecomethesun = new Song("Here come the sun","The Beatles","2:54"); //instance of song constructor function

playlist.add(herecomethesun); //we're calling the add method of playlist constructor and passing the variable 
                                                   // herecomethesun  which holds
                                                   // the instance of songs constructor function.

So by calling the add method of playlist constructor we're passing the instance of song constructor in it. That means, It is simple to access the properties and methods of song constructor function inside of playlist constructor functions.