constGreeters=[]for(vari=0;i<10;i++){Greeters.push(function(){returnconsole.log(i)})}Greeters[0]()//10Greeters[1]()//10Greeters[2]()//10constGreeters=[]for(leti=0;i<10;i++){Greeters.push(function(){returnconsole.log(i)})}Greeters[0]()//0Greeters[1]()//1Greeters[2]()//2第二个用let后面不应该是undefined吗。。还有为什么Greeters数组里保存的是[function(){returnconsole.log(i)},function(){returnconsole.log(i)},...,function(){returnconsole.log(i)}]而不是[function(){returnconsole.log(0)},function(){returnconsole.log(1)},...,function(){returnconsole.log(9)}]?
慕姐8265434
莫回无
相关分类