Answers for "Use getters and setters to Control Access to an Object"

0

Use getters and setters to Control Access to an Object

class Thermostat {
  constructor(fahrenheit) {
    this.fahrenheit = fahrenheit;
  }
  
  get temperature() {
    return (5 / 9) * (this.fahrenheit - 32);
  }
  
  set temperature(celsius) {
    this.fahrenheit = (celsius * 9.0) / 5 + 32;
  }
}
Posted by: Guest on April-20-2021
1

js why to use getters and setters

1) Syntax reasons. It’s easier and faster to read code 
created with accessor functions
2) Encapsulation. I can create safer code with accessor functions.
Posted by: Guest on June-02-2021

Code answers related to "Use getters and setters to Control Access to an Object"

Browse Popular Code Answers by Language