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 trialSam Parkash
6,645 PointsIs "this" the same as artist?
Hi,
Could someone please clarify with me if the word "this" is the same as "artist" in the following 3 lined piece of code...
function song(title, artist, duration){ Media.call(this, title, duration); this.artist = artist; }
So what i'm asking is if the word "artist" in the first line is the same as "this" in the second line.
1 Answer
Julie Myers
7,627 PointsThe quick answer is nope. Let's look at the coding:
function song(title, artist, duration) {
Media.call(this, title, duration);
this.artist = artist;
}
/*
In Media.call(); call() is a method.
You can invoke a function using the call() method. The first argument is the
object that will be used as the value of the this keyword. This allows you to set
and control what the this keyword is instead of relying on how javaScript is
designed to use the this keyword.
*/
Sam Parkash
6,645 PointsSam Parkash
6,645 PointsThanks :)
Julie Myers
7,627 PointsJulie Myers
7,627 PointsYou're welcome. :)