一个js 域问题,有一本书 叫 javasrcip pattert 好像是,写的很好,,
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div class="header"> <h1>test</h1> </div> <script> /*var scp="glob"; window.onload = function f(){ alert(scp); console.log(scp); //输出"undefined",而不是"glob" var scp="loca"; //在这里初始化 console.log(scp); //输出"loca" alert(scp+"22222"); } */ var scp="glob"; function f(){ alert(scp); console.log(scp); //输出"undefined",而不是"glob" var scp="loca"; //在这里初始化 console.log(scp); //输出"loca" alert(scp+"22222"); } f(); </script> </body> </html>
参考地址:http://www.cnblogs.com/zqzjs/p/4796242.html