for (var i = 0; i < 10; i++) { setTimeout(function() { console.log(i) }, 10) } 输出10个10 for (var i = 0; i < 10; i++) { (function(i){ setTimeout(function() { console.log(i) }, 10) })(i) }
输出0,1,2,3,4,5,6,7,8,9
原文:https://www.cnblogs.com/ladybug7/p/14088061.html