函数内的javascript函数

don*_*onk 3 javascript reflection scope

所以我想知道是否可以从范围外访问变量(具有函数值).我有这样的代码:

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

$(function(){
  // need to access childFunction() here.
});
Run Code Online (Sandbox Code Playgroud)

jon*_*ohn 6

var childFunction;

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

$(function(){
  childFunction();
});
Run Code Online (Sandbox Code Playgroud)