-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_object_3.html
More file actions
78 lines (47 loc) · 1.87 KB
/
3_object_3.html
File metadata and controls
78 lines (47 loc) · 1.87 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!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
// Property value shorthand
// 일반적인 오브젝트 형태로 값들 만들기.
const person1 = {name : 'bob', age : 2};
const person2 = {name : 'steve', age : 3};
const person3 = {name : 'dave', age : 4};
// + 하나하나 추가해야됨
// 좀 더 효율적인 방법으로 만들기.
// 함수에서 받은 파라미터를 오브젝트형태로 return 시키기
// es6에서 class가 없던시절 하던것
// function makePerson (name, age) {
// return {
// name: name,
// age : age
// };
// }
// const person4 = makePerson('juye',30);
// console.log(person4);
console.log('----------------------------------------')
// Constructor Function
function MakePerson (name, age) {
// 이 코드에선 this ={}
this.name = name;
this.age = age;
//return this; //가 생략된 형태다 -> js가 알아서 인식해줌
}
const person5 = new MakePerson('juye',30);
console.log(person5); // 주소 -> 레퍼런스라고함
console.log('----------------------------------------')
// in operatior : 오브젝트안에 프로퍼티가있는지 체크하는 방법.
// console.log( 'key' in obj ); 형태로 입력
// console.log('name' in person5);
// console.log('age' in person5);
// console.log('juye' in person5);
</script>
</body>
</html>