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

269
Views
Calling a function within a function from outside

I am having some trouble here trying to call function C from an onClick event on the page.

function leftArrowClicked() {
  functionA(functionC);
}

function functionA() {
  function functionB(w) {
    function functionC() {
      // do stuff
    };
  }
}
<div id="dashboard_left_arrow" onclick="leftArrowClicked()">Click</div>

But it's of course not working. Currently seeing 'functionC is not defined' in the console. I don't know much about nested functions, hence probably why my method isn't working. Any ideas?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use something called Modular Design Patterns. It goes something like this -- you can see that functionA is an function that is already invoked, so I can call functionB directly on that because it is returned inside an object. Calling functionC can be done on top of that.

var functionA = (function() {
  function functionB(w) {
    function functionC() {
      // do stuff
      return 'inside functionC';
    }
    return {functionC:functionC};
  }
  return {functionB:functionB};
})();

function leftArrowClicked() {
  console.log(functionA.functionB('').functionC());
}
<div id="dashboard_left_arrow" onclick="leftArrowClicked()">Click</div>

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!