1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4 <meta charset="UTF-8"> 5 <title></title> 6 </head> 7 <body> 8 <script> 9 10 // function fn(){ 11 // console.log(1); 12 // } 13 14 //匿名函数。 15 // (function (){ 16 // console.log(1); 17 // }) 18 19 20 //调用方法: 21 //1.直接调用 22 (function (){ 23 console.log(1); 24 })(); 25 26 //2.绑定事件 27 document.onclick = function () { 28 alert(1); 29 } 30 31 //3.定时器 32 setInterval(function () { 33 console.log(444); 34 },1000); 35 36 37 </script> 38 </body> 39 </html>