<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> /* 默认情况下是顺序结构, 代码会从上之下的执行, 前面的没执行完后面的不能执行 默认情况下通过var定义的变量, 只要不是定义在函数中都是全局变量 */ /*for(var i=0;i<3;i++)//前面的执行完后面的才会执行 { function test() { console.log(i); } } console.log(i); test();*/ /*for(var i=0;i<3;i++) { function test() { console.log(i); } test();//每次会执行到它 } */ /*for(var i=0;i<3;i++) { (function test() { console.log(i); })();//立即执行的闭包 }*/ for(var i = 0; i < 3; i++) { (function test(index) { console.log(index); })(i);//立即执行的闭包 } </script> </body> </html>
dom啦 循环索引同步1
关注
打赏