pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Javascript pastebin - collaborative debugging tool View Help


Posted by eocanha on Thu 2 Apr 10:44
report abuse | download | new post

  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>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post