Advertisement
Guest User

eocanha

a guest
Apr 2nd, 2009
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <body>
  3. <script type="application/javascript;version=1.7">
  4.  
  5. let funs = {};
  6. let msg = "";
  7.  
  8. for (let i = 0; i < 10; i++) {
  9.   funs[i] = function() {
  10.     msg += "i = " + i + "\n";
  11.   }
  12. }
  13.  
  14. for (let i = 0; i < 10; i++) funs[i]();
  15.  
  16. alert("Without redeclaration: \n"+msg);
  17.  
  18. msg = "";
  19. for (let i = 0; i < 10; i++) {
  20.   let idx = i;
  21.   funs[i] = function() {
  22.     msg += "i = " + idx + "\n";
  23.   }
  24. }
  25.  
  26. for (let i = 0; i < 10; i++) funs[i]();
  27.  
  28. alert("With redeclaration: \n"+msg);
  29.  
  30. </script>
  31. </body>
  32. </html>
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement