9/28/2018 - 2:06 AM

Getters and Setters

// When the property is accessed, the return value from the getter is used. 
// When a value is set, the setter is called and passed the value that was set. 
// It’s up to you what you do with that value, but what is returned from the setter is the value that was passed in – so you don’t need to return anything.
// Getter functions are meant to simply return (get) the value of an object's private variable to the user without the user directly accessing the private variable.

class Animal {
  constructor(species, color) {
    this.species = species,
    this.color = color
  static info() {
    console.log('Here is the info');
  get description() {
    console.log(`This is a description of the ${this.species}`);
  set newColor(value) {
    this.color = value; 
  get newColor() {
    return this.color;
const bear = new Animal('bear', 'brown');
bear.newColor = 'red'; // Set the color to a new color. then calls get function.