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

Why is there no argument in the playlist constructor function?

I thought that you always had to have arguments. Basically the same word that is after this.

In this exemple why is songs and/or nowPlayingIndex are not taken as arguments?

Thanks

can you please post the code you have a question about. Thanks!

2 Answers

It looks like it's a design choice. You could pass in the arguments if you would like. This would allow your Playlist object to take in a list of songs and set the nowPlayingIndex to something other than 0.

The way it is currently structured, you are forced to add songs individually and use the next method to change the nowPlayingIndex. There is nothing wrong with either method. To me, it looks like a simple design choice.

Oops sorry I thought the question was link to the video I was watching.

So it's for the javascript object oriented programming course and the video is playlist project, and here is the bit of code I was referring to.

function Playlist() {
    this.songs = [];
    this.nowPlayingIndex = 0;
}

the short answer right now and I'll explain in detail later is that the arguments passed are through the constructor of the constructor functions. exmp:

Playlist.prototype.add = function(song) {
  this.songs.push(song);
};

I'm sure someone can go in detail, or I can later today. In short look at the code above and you will find the arguments being used.