Say I have some complicated function that, through subsequent nested function calls, can potentially call itself, is there an accepted method to prevent this recursive call in the case where it is undesirable?
e.g.:
function h()
{
if(someOtherState)
f(); // uh-oh
}
function g()
{
if(someState)
h();
}
function f()
{
g();
}
Invoking Cunningham's Law here (I am not really a JS developer), a way I've found that works is:
function f()
{
if(f.inFunction)
return;
f.inFunction = true;
// Some complicated/non-deterministic code that may call f() again
f.inFunction = false;
}