//闭包:指有权访问另一个函数作用域中的变量的函数 function fun1() { var result = []; for (var i=0; i<10; i++) { result[i] = function () { return i; } } return result; } function fun2() { var result = []; for (var i=0; i<10; i++) { result[i] = function (num) { return function () { return num; } }(i) } return result; } var arr1 = fun1(); var arr2 = fun2(); for (var i=0; i<arr1.length; i++) { document.write(arr1[i]() + "<br />");//10 10 10 10 ... } for (var i=0; i<arr1.length; i++) { document.write(arr2[i]() + "<br />");//0 1 2 3 ... 9 }