JavaScript Getters and Setters

Posted by Joe Enos on March 13, 2021 · 1 min read

JavaScript has properties with getters and setters, just like languages such as C#. They don't seem to be as widely used. If you're defining an object and want to handle events, validate input, format output, etc., then properties are a good way to make that happen. Or you could also use Java-style getX/setX methods, which accomplish the same thing with a different syntax.

View code on GitHub