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

191
Views
NodeJS - Call Nested Function from inside another nested Function

i have two nested functions, i want to call the second one inside the first one but i nodejs doesn't seem to recognize it.

function Main(){
  this.NestedA = function(){
    console.log('Hello from A')
  }

  this.NestedB = function(){
    console.log('Hello from B')

    /* How to call NestedA from here? */
    /**
     * I tried
     * NestedA()
     * this.NestedA()
     */
  }
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I think you should not use this. Try this way:

function Main(){
  const NestedA = function() {
    console.log('Hello from A')
  }

  const NestedB = function() {
    console.log('Hello from B');
    NestedA();
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

What is this? Really, you should not need this. Just change the declaration to normal function declarations, you might even use const assignment for functions like NestedC below.

function Main(){
  function NestedA(){
    console.log('Hello from A')
  }
  const NestedC= () => {
    console.log('Hello from A')
  }

  function NestedB(){
    console.log('Hello from B')
    NestedA();
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

You could also return the function that you want to call, and call it such as:

 function Main() {
  this.NestedA = function () {
    console.log("Hello from A");
  };

  return (this.NestedB = function () {
    console.log("Hello from B");
  });
}

Main2()(); //Hello from B
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!