-
Notifications
You must be signed in to change notification settings - Fork 0
/
function_declare.html
84 lines (78 loc) · 2.1 KB
/
function_declare.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8"/>
<title>函数声明与函数表达式--javascript趣味探索系列,前端开发之Ginano</title>
<meta name="description" content="函数声明与函数表达式,javascript趣味探索系列,前端开发之Ginano"/>
<meta name="keywords" content="函数声明与函数表达式,javascript趣味探索系列,前端开发之Ginano"/>
<script type="text/javascript" language="JavaScript" src="src/common2.js"></script>
<link rel="stylesheet" href="src/common.css"/>
</head>
<body>
<pre id='script-source-code'>
//下面的代码验证了,解析器应该是先将所有的变量加入到上下文的变量列表中,并设值为undefined
//然后再把function进行解析同样加入到上下文的变量列表中
//在执行到当前作用域时则对var声明变量进行赋值操作
//最后按照逻辑流程进行处理
log(foo);
log(test);
var foo=function(){return 3;}
function foo(){
return 4;
}
function test(){
return 5;
}
var test=function(){
return 6;
}
//只有firefox会是1,其他IE6/opera/chrome都是2
if(true) {
function foo(){ return 1; }
}
else {
function foo(){ return 2; }
}
log(foo);
log(test);
log(foo());
//-------------------其他IE下的bug调试
log(typeof g);
var f = function g() {
return 7;
};
if (false) {
f = function g(){
return 8;
};
}
log(typeof g);
//------看看全局变量gg设置成功了没---
(function(){
gg = function gg(){};
log(gg);
})();
log(gg);
//----匿名函数的this-------
(function(){
log(this);
(function(){
log(this);
(function(){
log(this);
var dd=function sfd(){
log(this);
};
dd();
})();
})();
})();
//test the logic without order
testlogic();
log('maybe the first');
function testlogic(){
log('maybe the last');
}
</pre>
</body>
</html>