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

Matthew Russo
Matthew Russo
3,871 Points

Why not use: console.log(ernie._owner); ?

We added a getter method to get the _owner property and log it to the console, but what are the benefits of doing this? Would console.log(ernie._owner) have worked?

2 Answers

Steven Parker
Steven Parker
231,184 Points

That would certainly work just to log the owner of this particular object ("ernie"). But the code example is intended to show you how to create getter methods, which in actual practice would likely be used to do more complex things.

I was also wondering this same thing. Glad I looked here.