On Jul 14, 12:16 am, Guapo <[EMAIL PROTECTED]> wrote: > 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 ... > var globVar = outerFun(); > globVar.innerFun(); // Alerts "1" > globVar.innerFun2(); // Alerts "3" > globVar.innerFun(); // Alerts "4"
As i understand it, that code is wrong, as globVar.innerFun2() is not available to the caller at this point. IMO, to be legal code, "innerFun2()" should be replaced with "outerFun2()". See: http://javascript.crockford.com/private.html for why innerFun2() can be considered a "private" variable of globVar. > var globVar2 = outerFun(); > globVar2.innerFun(); // Alerts "1" > globVar2.innerFun2(); // Alerts "3" > globVar2.innerFun(); // Alerts "4" Same here.