Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Object-Oriented JavaScript Getters and Setters Object Interaction

Julianna Kahn
Julianna Kahn
20,701 Points

I can't tell from this video, is the Owner class being created "inside" the Pet class.

I'm trying to understand if a class can be set up inside a class.

3 Answers

Ian Ostrom
seal-mask
.a{fill-rule:evenodd;}techdegree
Ian Ostrom
Full Stack JavaScript Techdegree Student 10,305 Points

Think of the class as the mold and the object is what is mass produced by that mold. Both the owner and pet classes are independent. When the objects of each are created (instantiated) they each are a new entity with its own space in the memory of the computer.

When we call the owner setter method on the ernie object we are connecting the ashley object to it by referencing it in ernie's _owner property.

Julianna Kahn
Julianna Kahn
20,701 Points

That explains a lot, thank you.

Julianna Kahn
Julianna Kahn
20,701 Points

I don't understand when you say you can use a getter to use another class "inside that" class.

Jackson McComas
Jackson McComas
8,036 Points

Nope, classes cannot be nested in other classes. But you can use a getter though to use another class inside that class.