var a=[]; for(var i = 0; i < 10; i++) { a[i] = function() { return i; } } console.log(a[9]()); //10 console.log(i); //10
一直以为外部访问不到 i
var a=[]; for(var i = 0; i < 10; i++) { a[i] = function() { return i; } } console.log(a[9]()); //10 console.log(i); //10
一直以为外部访问不到 i
转载于:https://www.cnblogs.com/imeng/p/4892229.html