今天做一个循环想得到1,2,3...10的输出结果。自己写的放弃了,然后看到了这么一个方案,但不是很理解,不知道自己哪一方面知识的欠缺,求大神解答!!!varfuncs=[];for(vari=0;i<10;i++){funcs.push((function(value){returnfunction(){console.log(value);}}(i)));}funcs.forEach(function(func){func();//outputs0,then1,then2,upto9});自己访问自己的变量i,在每一个循环中都传入一个i值???
侃侃尔雅
相关分类