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 Getters

Jesse Dispoto
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jesse Dispoto
Front End Web Development Techdegree Graduate 14,538 Points

What would happen if I created the "activity" method without the keyword "get"?

Is the get keyword only used when creating dynamically changes methods within an object? Kinda confused about "get"

1 Answer

Steven Parker
Steven Parker
231,172 Points

Leaving off the "get" changes the access syntax. With an ordinary method, you must put parentheses after the name to invoke the method ("instance.activity()"). But with "get" you create a dynamic property that is accessed just by name ("instance.activity").

Steven Parker
Steven Parker
231,172 Points

It looks like you asked that question separately, take a look at my answer over there.

And if this question has been answered, you can mark it solved by choosing a "best answer'.
Happy coding!