FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Learning/Object.html at master · xiazhe/JavaScript-Learning · GitHub
xiazhe
/
JavaScript-Learning
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
4
Code
Issues
0
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Learning
/
Object.html
Copy path
More file actions
More file actions
Latest commit
History
History
History
104 lines (81 loc) · 2.45 KB
Breadcrumbs
JavaScript-Learning
/
Object.html
Copy path
File metadata and controls
104 lines (81 loc) · 2.45 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html
>
<
html
>
<
head
>
<
meta
http-equiv
="
Content-Type
"
content
="
text/html; charset=utf-8
"
/>
<
title
>
Object
</
title
>
<
meta
charset
="
utf-8
"
/>
</
head
>
<
body
>
<
script
>
//面对对象
var
Person
=
new
Object
(
)
;
//console.log(Person);
//Object {}
var
$error
;
//var a, b, c;
//c = 1;
//a = b || c;
//console.log(a);
//1
//function Person() {
//}
//Person.prototype.name = "尼古拉斯.赵四";
//Person.prototype.age = 25;
//Person.prototype.sayName = function () {
// console.log(this.name);
//}
//var person = new Person();
//person.sayName();
//对象创建
var
objA
=
new
Object
(
)
;
var
objB
=
{
}
;
//console.log(typeof objB); // "object"
//console.log(objA === objB); //false
// 克隆对象
function
clone
(
obj
)
{
// Handle the 3 simple types, and null or undefined
if
(
null
==
obj
||
"object"
!=
typeof
obj
)
return
obj
;
// Handle Date
if
(
obj
instanceof
Date
)
{
var
copy
=
new
Date
(
)
;
copy
.
setTime
(
obj
.
getTime
(
)
)
;
return
copy
;
}
// Handle Array
if
(
obj
instanceof
Array
)
{
var
copy
=
[
]
;
var
len
=
obj
.
length
;
for
(
var
i
=
0
;
i
<
len
;
++
i
)
{
copy
[
i
]
=
clone
(
obj
[
i
]
)
;
}
return
copy
;
}
// Handle Object
if
(
obj
instanceof
Object
)
{
var
copy
=
{
}
;
for
(
var
attr
in
obj
)
{
if
(
obj
.
hasOwnProperty
(
attr
)
)
copy
[
attr
]
=
clone
(
obj
[
attr
]
)
;
}
return
copy
;
}
throw
new
Error
(
"Unable to copy obj! Its type isn't supported."
)
;
}
//通过原型继承创建一个新对象
function
inherit
(
p
)
{
if
(
!
p
)
{
throw
TypeError
(
"p is not an object or null"
)
;
}
if
(
Object
.
create
)
{
return
Object
.
create
(
p
)
;
}
var
t
=
typeof
p
;
if
(
t
!==
"object"
&&
t
!==
"function"
)
{
throw
TypeError
(
"p is not an object or null"
)
;
}
function
f
(
)
{
}
;
f
.
prototype
=
p
;
return
new
f
(
)
;
}
</
script
>
</
body
>
</
html
>
Back
|
FazBrowse Home
|
New Git URL