Posted by eocanha on Thu 2 Apr 10:44
report abuse | download | new post
- <html>
- <body>
- <script type="application/javascript;version=1.7">
- let funs = {};
- let msg = "";
- for (let i = 0; i < 10; i++) {
- funs[i] = function() {
- msg += "i = " + i + "\n";
- }
- }
- for (let i = 0; i < 10; i++) funs[i]();
- alert("Without redeclaration: \n"+msg);
- msg = "";
- for (let i = 0; i < 10; i++) {
- let idx = i;
- funs[i] = function() {
- msg += "i = " + idx + "\n";
- }
- }
- for (let i = 0; i < 10; i++) funs[i]();
- alert("With redeclaration: \n"+msg);
- </script>
- </body>
- </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.