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 trialpraveen
11,314 PointsQuestion 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
231,269 PointsThe "Token" object constructor uses a Player object as the second argument, not just the player's name.
Trevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 PointsTrevor Maltbie
Full Stack JavaScript Techdegree Graduate 17,021 PointsInside 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
231,269 PointsSteven Parker
231,269 PointsThe keyword "this" would refer to the current instance of the class, not class "Player" itself.
Matt Coale
Full Stack JavaScript Techdegree Graduate 17,884 PointsMatt Coale
Full Stack JavaScript Techdegree Graduate 17,884 PointsThat explained it for me. Thanks!