the following text if copy from the book,I was confused with the variable globVar in the innerFun2,is it a clerical error or the variable in the statement "var globVar = outerFun();"? thank you all! ==================================== Interactions between Closures When more than one inner function exists, closures can have effects that are not as easy to anticipate. Suppose we pair our incrementing function with another function, this time incrementing by two: function outerFun() { var outerVar = 0; function innerFun() { outerVar++; alert(outerVar); } function innerFun2() { outerVar = outerVar + 2; alert(globVar); } return {'innerFun': innerFun, 'outerFun2': outerFun2}; } We return references to both functions, using a map to do so (this illustrates another way in which reference to an inner function can escape its parent). Both functions can be called through the references:
var globVar = outerFun(); globVar.innerFun(); // Alerts "1" globVar.innerFun2(); // Alerts "3" globVar.innerFun(); // Alerts "4" var globVar2 = outerFun(); globVar2.innerFun(); // Alerts "1" globVar2.innerFun2(); // Alerts "3" globVar2.innerFun(); // Alerts "4"