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 Object Interaction

Julianna Kahn
Julianna Kahn
20,702 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,331 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,702 Points

That explains a lot, thank you.

Julianna Kahn
Julianna Kahn
20,702 Points

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

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