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

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

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

0

function myFunct() { 
    function tryIt() {
        console.log("hi");
    }
    return {
        tryIt: tryIt
    };
}
var foo = myFunct();
foo.tryIt();
about 4 years ago · Santiago Trujillo 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