Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
could not call a function that is defined in another

What I have tried:

var func1 = (function() {
function func2() {
console.log("wrkng");
};
})();
how can i call func2()???
func1.func2(); gives error saying func1 is undefined..
Posted
Updated 22-Aug-16 19:02pm

You Cannot! since it is a private function, use Module pattern[^] to expose it outside as
JavaScript
var func1 = (function () {
           func2 =  function() {
                console.log("wrkng");
           };
           return {func2:func2}

        })();


JavaScript
func1.func2()
 
Share this answer
 
v2
AFAIK, you can't. The visibility scope of the inner function is limited to the function it is defined in.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900