How could this be done without repeating "DoTheNextThing();"?
if (dosomething)
DoSomething(function () {
DoTheNextThing();
})
else
DoTheNextThing();
I haven’t tried anything else because I can’t think of anything else to try.
2
Answers
It’s not pretty, but you can use a function that just calls its argument, and assign it conditionally to a variable.
Instead of
DoSomething
, choose a function that does nothing and then calls the callback:However, assuming
DoSomething
is an asynchronous function, you really should rewrite it to return a promise, then useasync
/await
for much cleaner code: