- <html>
- <head>
- <title>函数提升</title>
- <script language="javascript" type="text/javascript">
-
-
- function foo()
- {
- alert("global foo");
- }
-
- function bar()
- {
- alert("global bar");
- }
-
-
- var v = "global var";
-
- function hoistMe()
- {
- alert(typeof foo);
- alert(typeof bar);
- alert(v);
-
-
-
-
-
- foo();
- bar();
-
-
- function foo()
- {
- alert("local foo");
- }
-
-
- var bar = function()
- {
- alert("local bar");
- };
-
-
-
- var v = "local";
- }
-
- (function()
- {
- hoistMe();
-
- })();
-
-
-
- </script>
-
- </head>
- <body>
- </body>
- </html>
Javascript中函数及变量定义的提升
原文:http://www.cnblogs.com/xiaotaiyang/p/4617863.html