试图通过i
进入封闭来使它局部避免i
关闭问题基本维持在2为什么我不能传递的参数在起作用for循环
var myFunctions = {};
for (var i = 0; i < 3; i++) { // let's create 3 functions
myFunctions[i] = function(i) { // and store them in myFunctions
console.log("My value: " + i); // each should log its value.
};
}
for (var j = 0; j < 3; j++) {
myFunctions[j](); // and now let's run each one to see
}
// > "My value: undefined
// > "My value: undefined
// > "My value: undefined
那么当你调用函数,你** **不传递参数。 – Pointy
我是一个白痴:) – js2015
调用它像'myFunctions [j](j);' – Redu