Created
May 24, 2017 13:27
-
-
Save Barolina/62560c48c5de54bcf8286bfc0cf71d85 to your computer and use it in GitHub Desktop.
js замыкания
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result=[]; | |
for (var i = 0; i<5; i++){ | |
result[i] = (function(x){ | |
console.log(x); | |
})(i); | |
}; | |
result[0](); | |
result[1](); | |
result[2](); | |
result[3](); | |
result[4](); | |
console.log("---------------------------"); | |
var result=[]; | |
for (let i = 0; i<5; i++){ | |
result[i] = function (){ | |
console.log(i); | |
}; | |
}; | |
result[0](); | |
result[1](); | |
result[2](); | |
result[3](); | |
result[4](); | |
Author
Barolina
commented
May 24, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment