-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.js
224 lines (151 loc) Β· 3.72 KB
/
object.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
var emptyObject = {};
console.log(typeof emptyObject);
//κ°μ²΄ 리ν°λ΄ λ°©μ
var person = {
name: "Lee",
gender: "male",
sayHello: function(){
console.log("Hi! My name is " + this.name);
}
};
console.log(typeof person);
console.log(person);
person.sayHello();
//object μμ±μ ν¨μ
var people = new Object(); //λΉ κ°μ²΄μ μμ±
people.name = "Lee";
people.gender = "male";
people.sayHello = function(){
console.log("Hi! My name is " + this.name);
};
console.log(typeof people);
console.log(people);
people.sayHello();
//μμ±μ ν¨μ
var person1 = {
name: "Lee",
gender: "male",
sayHello: function(){
console.log("Hi! My name is " + this.name);
}
};
var person2 = {
name: "Kim",
gender: "female",
sayHello: function(){
console.log("Hi! My name is " + this.name);
}
};
//μμ±μ ν¨μλ₯Ό μ¬μ©νλ©΄ νλ‘νΌν°κ° λμΌν κ°μ²΄ μ¬λ¬ κ°λ₯Ό κ°νΈνκ² μμ±ν μ μλ€.
function Person(name, gender){
this.name = name;
this.gender = gender;
this.sayHello = function(){
console.log("Hi! My name is " + this.name);
};
}
var person1 = new Person("Lee", "male");
var person2 = new Person("Kim", "female");
console.log("person1: ", typeof person1);
console.log("person2: ", typeof person2);
console.log("person1: ", person1);
console.log("person2: ", person2);
person1.sayHello();
person2.sayHello();
function Person(name, gender){
var married = true; // private
this.name = name;
this.gender = gender;
this.sayHello = function(){
console.log("Hi! My name is " + this.name);
};
}
var person = new Person("Lee", "male");
console.log(typeof person);
console.log(person);
console.log(person.gender);
console.log(person.married);
var person = {
"first-name": "Ung-mo",
"last-name": "Lee",
gender: "male",
1: 10,
function: 1
};
console.log(person);
var person = {
'first-name': 'Ung_mo',
"last-name": "Lee",
gender: "male",
1: 10
};
console.log(person);
console.log(person['fisrt-name']);
console.log(person.gender);
console.log(person["gender"]);
console.log(person["1"]);
console.log(person[1]);
//νλ‘νΌν° κ° κ°±μ
var person = {
"first-name": "Ung-mo",
"last-name": "Lee",
gender: "male",
};
person["first-name"] = "Kim";
console.log(person["first-name"]);
//νλ‘νΌν° λμ μμ±. κ°μ²΄κ° μμ νμ§ μμ νλ‘νΌν° ν€μ κ°μ ν λΉνλ©΄
//μ£Όμ΄μ§ ν€μ κ°μΌλ‘ νλ‘νΌν° μμ±νμ¬ κ°μ²΄μ μΆκ°
var person = {
"first-name": "ung-mo",
"last-name": "lee",
gender: "male",
}
person.age = 19;
console.log(person);
delete person.gender;
console.log(person.gender)
var person = {
"first" : "ung-mo",
"last" : "lee",
gender: "male",
};
console.log(person);
for (var prop in person){
console.log(prop + ": "+ person[prop]);
}
var array = ["one", "two"];
for (var index in array){
console.log(index + ":"+array[index]);
}
const arr = [1,2,3];
arr.name = "my array";
for (const value of arr){
console.log(value);
}
for (const [index, value] of array.entries()){
console.log(index, value);
}
var foo = {
val: 10
}
var bar = foo;
console.log(foo.val, bar.val);
console.log(foo === bar);
bar.val = 20;
console.log(foo.val, bar.val);
console.log(foo === bar);
var a = 1;
var b = a;
console.log(a,b); // 1,1
console.log(a === b); // true
a = 10;
console.log(a,b); // 10 , 1
var foo = {
val : 10
}
var bar = foo;
console.log(foo.val, bar.val);
bar.val = 20;
console.log(foo.val, bar.val);
// λ³μ barμ λ³μ fooμ κ°μ ν λΉνμλ€. λ³μ fooμ κ°μ μμ±λ κ°μ²΄λ₯Ό κ°λ¦¬ν€λ μ°Έκ³ κ°.
// λ³μ barμλ κ°μ μ°Έμ‘°κ°μ΄ μ μ₯