A common closure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
function createFunction() {
var result = new Array;
// for(var i = 0; i < 10; iPP) {
// result[i] = function(num) {
// return function() {
// return num;
// }
// }(i)
// }
for(let i = 0; i < 10; iPP) {
result[i] = function() {
return i;
}
}
return result;
}
var arr = createFunction();
alert(arr[0]());
alert(arr[1]());
</script>
</body>
</html>
if you are declaring I with var, when you execute arr [0] (), access the scope chain up, then iDiver2, all output 2;
but if it is let declaration I, when you execute arr [0] (), is there I in the active object of createFunction, and if so, how is its value determined?