Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

339
Views
Is there an idiomatic way to prevent recursive function calls in JavaScript?

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();
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!