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 Token Properties Solution

Crystal Vesely
Crystal Vesely
14,391 Points

Why 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
Steven Parker
231,236 Points

You 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
Crystal Vesely
14,391 Points

Thank you so much! That response was extremely helpful. I see your responses quite often! I really appreciate your insight!