Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda