get
and set
are special keywords that behave like properties, the name of which is the same for both because they both relate to the same backing variable (the one with the underscore prefix). We cannot call them directly because they are engaged in the background.
Above we must assume that the value has already been set, and we’re only polling the variable for its current value. When we write,
console.log(robot.property);
we are accessing the getter, which then returns the backing variable value the same way a typical object would, and when we write,
robot.property = "some value";
we are accessing the setter, but it depends upon the getter for some special binding which I don’t really understand well enough to explain but if you can handle dry technical reading, I recommend digging deeper into the relationship, and why setters depend upon getters in the first place. We can’t have set without get for the variable in question.