Error: maximum call stack size exceeded --> ES6: Use getters and setters to Control Access to an Object

Error: maximum call stack size exceeded --> ES6: Use getters and setters to Control Access to an Object
0

#1

Hi Guys,

I am working using constructor functions to create, set, and get the temperature of a created thermos object in class Thermostat. Below is the code that I was able to come up with, and the test gives back an error stating “Maximum call stack size exceeded”.

I copy/pasted the challenge into Sublime text editor and ran it on Chrome, showing the error to be at the set property. My syntax is very similar to the constructor example given in the challenge description. Research into what a call stack is shows that I may have somehow created some sort of never ending loop, but I don’t seem to see it, my understanding on constructor functions hasn’t solidified yet.

class Thermostat{ constructor(Fahrenheit) { this.temperature = Fahrenheit; } get temperature(){ return 5/9 * (this.temperature - 32); } set temperature(newTemp){ this.temperature = newTemp * 9.0 / 5 + 32; } }

I am keeping track of the temperature within the constructor in Fahrenheit. To set .temperature, I pass a newTemp parameter through and convert to Celsius.

What gives? Thanks in advance.


#2

Nevermind! I figured out my mistake. Do I delete this thread?


#3

Nah, but you can check it off as solved. There’s no delete thread button.