Skip to content

Instantly share code, notes, and snippets.

@Barolina
Created May 24, 2017 13:27
Show Gist options
  • Save Barolina/62560c48c5de54bcf8286bfc0cf71d85 to your computer and use it in GitHub Desktop.
Save Barolina/62560c48c5de54bcf8286bfc0cf71d85 to your computer and use it in GitHub Desktop.
js замыкания
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]();
@Barolina
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment