-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.js
More file actions
138 lines (105 loc) · 2.21 KB
/
api.js
File metadata and controls
138 lines (105 loc) · 2.21 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
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
// this
function person(){
this.age = 22
return {
name: 'kim',
age: 44,
getAge: () => {
console.log(this.age) // 22
}
}
}
const p = person()
p.getAge()
console.log('kim'.indexOf('i',2))
console.log('hello'.match('[^ab]'))
console.log(Number.parseInt('123a4'))
// unshift, push
let arr = [1,2,3]
arr.unshift(4,5,6);
arr.push([7,8,9])
console.log(arr);
// reduce
arr = [100, 200, 300, 400]
let result = arr.reduce((acc,curr) => {
return acc + curr
}, 0)
console.log(result)
// Object.assign()
source = {a :1, b: 2}
source2 ={c: 3, b: 9}
target = {d :5, e: 6}
Object.assign(target, source, source2)
console.log(target)
function User(firstName, lastName){
this.firstName = firstName
this.lastName = lastName
}
// prototype
User.prototype.getFullName = function() {
return `${this.firstName} ${this.lastName}`
}
const taejunKim = new User('Taejun', 'Kim')
const heropy = new User('HEROPY', 'Park')
console.log(taejunKim.getFullName())
console.log(heropy.getFullName())
console.log(taejunKim.getFullName === heropy.getFullName)
console.log(taejunKim)
// class
class ClassUser{
constructor(firstName, lastName){
this.firstName = firstName
this.lastName = lastName
}
get getFullName(){
return `${this.firstName} ${this.lastName}`
}
}
const taejun = new ClassUser('Taejun', 'Kim')
console.log(taejun.getFullName)
// class - extends
class Car{
constructor(name, wheel){
this.name = name
this.wheel = wheel
}
start(){
return true
}
}
class Bus extends Car{
constructor(name, wheel, license){
super(name, wheel)
this.license = license
}
start(){
if(this.license.isValid){
return true
}
throw '무면허'
}
}
// 전개 연산자
const arr1 = [1, 2, 3, 4]
const arr2 = [4, 5, 6]
const arrWrap = [arr1, arr2]
console.log(arrWrap)
// 구조 분해 할당.
const [x, , y, z, t = 20] = arr1
console.log(x) // 1
console.log(y) // 3
console.log(z) // 4
console.log(t) // 20
const objA = {
a: 1,
b: 2,
c: 3
}
const {a, b:myKey} = objA
console.log(a)
console.log(myKey)
// 깊은 복사
arrOrigin = [1,2,3]
arrCopy = _.cloneDeep(arrOrigin)
arrOrigin[0] = 10
console.log(arrCopy[0])