Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var a = 1;
  2.  
  3. var six = (function() {
  4.     var foo = 6;
  5.  
  6.     return function() {
  7.         // JavaScript "closure" means I have access to foo in here,
  8.         // because it is defined in the function in which I was defined.
  9.     alert(foo);
  10.   };
  11. })
  12.  
  13. ();
  14.  
  15. six();      // alerts 6
  16. alert(a);   // alerts 1
  17. alert(foo); // ReferenceError: foo is not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement