)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Object Getter Setter

  1. const book = {
  2.   get name() { 
  3.     return this.title ?? 'no title'; 
  4.   },
  5.   set name(val) { 
  6.     document.
  7.       body.
  8.       innerHTML += `name changed to "${val}"<br>`;
  9.     this.title = val; 
  10.   }
  11. };
  12.  
  13. console.log(book.name);
  14. book.name = 'Math Book';
  15. book.name = 'JavaScript Book';

Getter setter syntax for Object literal.

snippet.zone ~ 2021-22 /// {s/z}