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 Getters and Setters Setters

Christian van Lierop
Christian van Lierop
13,758 Points

Confusion by naming conventions owner(owner)= owner...

I always get confused by these naming conventions;

set owner(owner) { this._owner = owner; }

So the setter method is called "owner" and the parameter is called "owner" and then the property is also called "_owner"

How do I distinguish later what I'm referring to?

Wouldn't it be more understandable to write something like:

set ownetSet(ownerPar) { this.ownerProp = ownerPar; }

Am I missing something important?

1 Answer

Steven Parker
Steven Parker
231,248 Points

Your alternative would also work just fine. But remember that the scope of the parameter is limited to function, so you won't need to (or be able to) access it directly later. That's why it's being copied into the private field.

And the private field can be identified by the underscore in front of the name, which is a naming convention that implies a private field.