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: Challenge Building Constructor Methods and Generating Objects createTokens() Method Solution

Question about `this` being passed as a parameter in the createTokens() method

In this line : let token = new Token(i, this); what is the purpose of this , why not this.name?

1 Answer

Steven Parker
Steven Parker
231,248 Points

The "Token" object constructor uses a Player object as the second argument, not just the player's name.

Trevor Maltbie
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Trevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 Points

Inside of the class Player, every time the keyword "this" is used, it is referencing Player, right? so even in let token = new Token(i, this), this = Player. I don't think this really helps me understand what is going on here but at least I can say this = Player. right? idk. I'm going to keep moving forward and hope this stuff starts to make some sense.

Steven Parker
Steven Parker
231,248 Points

The keyword "this" would refer to the current instance of the class, not class "Player" itself.