Jump to content


Photo

Why By The Func2 We Mean The Inner Function


  • Please log in to reply
No replies to this topic

#1 lse123polis

lse123polis

    Active Member

  • Members
  • PipPip
  • 40 posts

Posted 18 March 2012 - 09:43 AM

why by the func2 we mean the inner function? '2' says anything...? p.459 Appx:#9. see below:

function func1(x) { 
 var tmp = 3;
 return function (y) {
  alert(x + y + (++tmp));
 } 
}
var func2 = func1(2);  // func2 is now a closure.
func2(10);
Again, tmp is in the local scope, but the func2 function is in the global scope. The above
function will also alert 16, because func2 can still refer to x and tmp, even though it is no
longer directly inside the scope.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users