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

147
Views
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 answers
Answer question

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 Report

0

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