FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-code/javascript-based/reference.js at master · rockhe168/javascript-code · GitHub
rockhe168
javascript-code
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-code
/
javascript-based
/
reference.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
84 lines (54 loc) · 934 Bytes
Breadcrumbs
javascript-code
/
javascript-based
/
reference.js
Copy path
File metadata and controls
84 lines (54 loc) · 934 Bytes
Raw
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*正常的情况*/
var
a
=
5
;
var
b
=
a
;
b
+=
3
;
alert
(
b
)
;
//8
alert
(
a
)
;
//5
//对象和函数都是引用的关系
var
a
=
[
1
,
2
,
3
]
;
var
b
=
a
;
b
.
push
(
4
)
;
alert
(
b
)
;
//1,2,3,4
alert
(
a
)
;
//1,2,3,4*/
//数组重新写
var
a
=
[
1
,
2
,
3
]
;
var
b
=
a
;
b
=
[
1
,
2
,
3
,
4
]
;
alert
(
b
)
;
//1,2,3,4
alert
(
a
)
;
//1,2,3
/*对象赋值*/
var
obj
=
{
a
:
10
}
;
var
obj2
=
obj
;
obj2
.
a
=
20
;
alert
(
obj
.
a
)
;
//20*/
//赋值解决方案
var
obj
=
{
a
:
10
}
;
function
copy
(
obj
)
{
//浅拷贝
var
newObj
=
{
}
;
for
(
var
attr
in
obj
)
{
newObj
[
attr
]
=
obj
[
attr
]
;
}
return
newObj
;
}
var
obj2
=
copy
(
obj
)
;
obj2
.
a
=
20
;
alert
(
obj
.
a
)
;
//10
//解决方案二
function
deepCopy
(
obj
)
{
//深拷贝
if
(
typeof
obj
!=
'object'
)
{
console
.
trace
(
)
;
return
obj
;
}
var
newObj
=
{
}
;
for
(
var
attr
in
obj
)
{
newObj
[
attr
]
=
deepCopy
(
obj
[
attr
]
)
;
}
return
newObj
;
}
var
obj2
=
deepCopy
(
obj
)
;
obj2
.
a
.
b
=
20
;
alert
(
obj
.
a
.
b
)
;
//10
Back
|
FazBrowse Home
|
New Git URL