-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext1.html
More file actions
46 lines (46 loc) · 950 Bytes
/
text1.html
File metadata and controls
46 lines (46 loc) · 950 Bytes
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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var a = [],b=[];
// 使用闭包处理循环输出i的问题
// for (var i = 0; i < 10; i++) {
// a[i] = function (i) {
// return function(){
// console.log(i);
// }
// }(i);
// }
// a[8](); // 8
// 使用let声明块级作用域
for(let i =0;i<10;i++){
b[i] = function(i){
return function(){
console.log(i)
}
}(i)
}
b[6]();
// alert(i);
// 使用let声明变量时每次循环都会是一个新的i
// let不存在变量提升
// console.log(c);
// let c = 0;
var x = 0;
var ary = [];
function show() {
return x++;
}
for(let i =0;i<3;i++){
ary[i] = show();
console.log()
}
console.log(ary);
// alert(xx);
</script>
</body>
</html>