ES6 how to avoid nested functions I have functions nested here in setTimeout

function startWorker (obj) {
  if (!code) {
    return setTimeout(2000, () =&gt; {
      startWorker(obj)
    });
  }

  console.log('worker started')
}


How do I correctly use startWorker as the callback without using more functions than needed.

What I'm trying to do:

I'm trying to run the same function with the same argument as the callback to a setTimeout inside without duplicating function calls.
I'm not sure I understand what you're asking, but what if you just use setInterval() instead of setTimeout()?



function startWorker(obj) {
  if (!code) {
    setInterval( () =&gt; {
      console.log(obj.action);
    }, 2000);
  }
}

const code = false;
const someObj = {
  action: "tick"
};

startWorker(someObj);