• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

186
Vistas
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?

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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>

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda