O'Reilly Forums: Why By The Func2 We Mean The Inner Function - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Why By The Func2 We Mean The Inner Function '2' says anything...? p.459 Appx:#9.

#1 User is offline   lse123polis 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 40
  • Joined: 04-October 09

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users