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!
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
Jesse DispotoFront End Web Development Techdegree Graduate 14,538 Points
Does it matter what order you invoke the getter and setter methods? Does get always go before set?
Does set always follow get, or could you put set before get?
Steven Parker228,001 Points
You would normally invoke "set" first, or else there would not be anything to "get".
But if you're talking about the order they are defined in the class, that makes no difference.
Thanks for the correction on methods inside classes. Though, in trying to confirm what you've said I've had trouble finding a clear answer for why the order of class methods doesn't matter.
According to MDN's documentation classes are not hoisted. However, I've also read that classes are hoisted, but just not initialized until evaluated thus the reason for not calling a class' functions until after the object is instantiated.
This post also says that hoisting of functions happens within block scope. So am I correct in concluding this is the reason that the order of functions within a class do not matter? Or is it only that we could never have a function inside a class that can directly call another function in that class? I couldn't come up with any.