Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement