Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript function within the function

So I was wondering if it is possible to access a variable (which has a value of function) from outside the scope. I have code that goes something like this:

function parentFunction(){
  var childFunction = function() {
    // do something
  }
}

$(function(){
  // need to access childFunction() here.
});
like image 507
donk Avatar asked Dec 30 '25 11:12

donk


1 Answers

var childFunction;

function parentFunction(){
  childFunction = function() {
    // do something
  }
}

$(function(){
  childFunction();
});
like image 91
jondavidjohn Avatar answered Jan 02 '26 01:01

jondavidjohn