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 trialJuneau Lim
13,362 PointsIf the getter/setter of JavaScript a bit different from Java's?
When I study Java, getter/setters were usually for encapsulation.
Talking about that, the meaning about encapsulation as well, feel a bit different from what I learned from Java. in there, encapsulation meant hide instants/methods as private from outside of class. But in the Javascript course, it was told that encapsulation is holding many elements as one package, and it seems like they are keeping the variable private as a convention by using _.
back to getter/setter, in Java, I mainly used it to access private variables. However, in here, getter was used to get a computed result of variables. And setter was used for assigning new property that didn't exist before, while in Java I used to use the setter to change the value of an existing variable.
It also seems like we are overloading getter/setter. is that the case?
Is the difference came from the fact that JavaScript is a dynamic language, or because it is web focussed?