Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
how to access to a function inside a funtion

I'm trying to call a function inside a function outside the main one:

var myFunction = function myFunct(element) {
   function tryIt(){
          alert("hello");
   };
   return{
     tryIt: tryIt
  }
}

And I'm try to call "tryIt" function outside myFunct with

myFunction.tryIt

But it doesnt work.

how can I do this?

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

First, you need is to call the function and then call the function of the returned object of the property tryIt.

var myFunction = function myFunct(element) {
        function tryIt(){
            alert("hello");
        }
        return {
            tryIt: tryIt
        };
    };

myFunction().tryIt();
//        ^^            calls myFunction
// ^^^^^^^^^            returns object with function tryIt
//                ^^    calls tryIt

about 4 years ago · Santiago Trujillo Denunciar

0

function myFunct() { 
    function tryIt() {
        console.log("hi");
    }
    return {
        tryIt: tryIt
    };
}
var foo = myFunct();
foo.tryIt();
about 4 years ago · Santiago Trujillo 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda