JS is different than some languages. In some languages, you would create setters and getters as methods like “setWriter” and “getWriter”, and that is how you would access them, like:
const writer = myBook.getWriter();
But JS doesn’t do it that way. You define the methods with the “get” and “set” keywords (as you’ve done above) and you just access the setter and getter as you would a property:
and JS just knows to use the getter for the first one and the setter for the second one, because of context. The code above doesn’t know that it is using a getter and setter, and it doesn’t care.
I understand the usage of getter and setter, but in this example, where are we getting the “writer()” from?
In short, that name “writer” is the name of the “pseudo property” you will be accessing in the code. Again, we just access myBook.writer and JS knows whether it is a standard property, and if not, it knows to use the setter or getter.
You aren’t the only one who finds this challenge a little confusing Don’t overthink it. This challenge is merely exposing you to getters and setters in JS. The challenge itself doesn’t have to make perfect sense. You just need to understand what getters and setters are and how they work. You may never use them yourself (they are not mandatory and some people think they make the language more confusing and don’t really help much). But there is a chance that you will run into them so you need to at least know what they are.
Do you understand what getters/setters are and how you use them?