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 trialChristian Pineault
7,291 PointsWhy 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
2 Answers
Fredrick Rogers
26,349 PointsIt 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.
Christian Pineault
7,291 PointsOops 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;
}
Jacob Mishkin
23,118 Pointsthe 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.
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointscan you please post the code you have a question about. Thanks!