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
john larson
16,594 Pointsthis in a constructor...
the commented out parts, I'm wondering if I understand 'this' in these circumstances. I think it's what the teacher said but I wanted to double check.
var City = function(name, state){
// this refers to what City is GOING to be
this.name = name || "Portland";
this.state = state || "Oregon";
};
portland = new City();
seattle = new City("Seattle", "Washington");
// this refers to new instance of City
console.log(portland);
console.log(seattle);
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! In this case, this refers to the object that's currently being made and stored in City. Hope this helps!
john larson
16,594 Pointsjohn larson
16,594 Pointstack sjรคlv!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherBtw, my native language is English
john larson
16,594 Pointsjohn larson
16,594 PointsMy grandmother and grandfather were born in smalland, so I'm guessing you have never been there then.