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 trialCrystal Vesely
14,499 PointsWhy aren’t we using ${this.owner.id} instead of ${owner.id}?
I understand that when we pass “this” as an argument for the parameter “owner”, we are essentially saying…
let token = new Token(i, this)
class Token {
constructor(index, owner) {
this.owner = owner;
this.id = token-${i}-${this.id}
}
}
But I don’t understand why we aren’t putting ${this.owner.id}.
1 Answer
Steven Parker
231,248 PointsYou certainly could use this.owner.id instead, since in the previous line this.owner was assigned to owner. But it's unnecessarily verbose because owner is still in scope and you can access owner.id directly.
Crystal Vesely
14,499 PointsCrystal Vesely
14,499 PointsThank you so much! That response was extremely helpful. I see your responses quite often! I really appreciate your insight!