-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_object_1.html
More file actions
58 lines (39 loc) · 1.42 KB
/
3_object_1.html
File metadata and controls
58 lines (39 loc) · 1.42 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Object
// literals and properties
// 이렇게 쓰면 데이터를 너무 번거롭게 관리해야함.
const name = 'juye';
const age = 30;
function print(name, age) {
console.log(name);
console.log(age);
}
print(name,age);
// 오브젝트로 만들면, name 과 age를 function에서매개 변수로 안받아도된다.
const juye = { name : 'juye', age : 30 };
function print2(person) {
console.log(person.name);
console.log(person.age);
}
print2(juye);
// 오브젝트를 만드는 방법.
const obj = {}; // object literal syntax <- js는 이게 가능함.
const obj2 = new Object(); // object constructor syntax <- class로 만드는거
// 중간에 프로퍼티추가도 가능함(하지만 비추)
juye.hasJob = 'true';
console.log( juye.hasJob); // true
// 프로퍼티 추가된거 삭제도 가능함
delete juye.hasJob
console.log( juye.hasJob); // undifined
</script>
</body>
</html>