Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
69 lines (52 loc) · 1.87 KB

File metadata and controls

69 lines (52 loc) · 1.87 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script>
window.onload = function () {
// 封闭函数,协作开发中如果同事写了10万行代码,其中包含func1的函数
// 自己不会全部阅读同事的10万行代码去避免自己也定义func1的函数
// 同事的函数func1
function func1() {
console.log(1);
}
func1()
// 自己的函数func1
function func1() {
console.log(111111);
}
// 执行的时候会发现,同事的func1并不会执行,只会执行两次自己的11111打印
func1()
// 封闭函数解决的就是同名函数冲突的情况下,造成某个函数无法执行,保证两个函数都执行
function func2() {
console.log(2);
}
func2()
;(function () { // 使用;开头或者多个分号开头,小括号包含的类似匿名函数的形式
function fun2() {
console.log(222222);
}
fun2()
})()
!function () { // 封闭函数2
function fun2() {
console.log(222222);
}
fun2()
}()
~function () { // 封闭函数3
function fun2() {
console.log(222222);
}
fun2()
}()
}
</script>
</head>
<body>
</body>
</html>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.