Understand : Use getters and setters to Control Access to an Object


I would like to correctly understand what is it explain in this course.
Are my comments rights ?

class Book {
  constructor(author) { /* is used by const lol = new Book('anonymous'); */
    this._author = author;
  // getter
  get writer(){ /* is used by console.log(lol.writer); */
    return this._author;
  // setter
  set writer(updatedAuthor){ /* is used by lol.writer = 'wut'; */
    this._author = updatedAuthor;
const lol = new Book('anonymous');
lol.writer = 'wut';

For example, if I use const lol = new Book('anonymous'); only, we’ll only use the constructor part, is that right ?
Maybe I’m completly wrong haha :sweat_smile:

Thanks in advance,

Link to the challenge:

When you instanciate and object like new Boo('superman') the first method or function that call automatically is the constructor, that way you can pass data like ‘superman’, but when you create an instance you have access to all the methods that have that class

1 Like