0

I am trying to understand recursion and tail call optimization. I have this example code below and it seems not to be TCO. Why is it not and how can I change it to be optimized?

const getState = () => {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', 'https://stackoverflow.com', true);
  xhr.onload = () => console.log(xhr.response);
  xhr.send();
};

(function updateState() {
  getState();
  setTimeout(updateState, 1000);
})();
The Fool
  • 16,715
  • 5
  • 52
  • 86
  • had you seen this: https://stackoverflow.com/questions/37224520/are-functions-in-javascript-tail-call-optimized – Edwin May 08 '19 at 17:13
  • @Edwin on a second look it seems related and the material provided is interesting & useful for my understanding. Still, I am looking for an up to date implementation example here on SO. – The Fool May 08 '19 at 18:10

0 Answers0