在下面的函数中为什么arr包含一个函数而不是x的值?在第二个函数中为什么数组元素未定义
function makeFunctionArray3() {
console.log('three')
const arr = []
for (var i = 0; i < 5; i++) {
arr.push(
(function(x) {
return (function() {
console.log(x)
})
})(i)
)
}
return arr
}
functionArr = makeFunctionArray3()
functionArr[3]()
console.log(functionArr)
function makeFunctionArray4() {
console.log('four')
const arr = []
for (var i = 0; i < 5; i++) {
arr.push(
(function(x) {
return console.log(x)
})(i)
)
}
return arr
}
functionArr = makeFunctionArray4()
console.log(functionArr)