1️⃣ 객체 지향 프로그래밍
- Object Oriented JavaScript, OOP
- 하나의 모델이 되는 청사진(blueprint)를 만들고, 그 청사진을 바탕으로 한 객체(object)를 만드는 프로그래밍 패턴
- 청사진 -> class
- 객체 -> instance
2️⃣ class 작성
3️⃣ constructor
class Car {
constructor(brand, name, color) {
}
}
3️⃣ instance
let avante = new Car('hyundai', 'avante', 'black')
3️⃣ extends, super
4️⃣ extends
4️⃣ super
class avante extends Car {
constructor(brand, name, color) {
super()
}
}
class Sneakers {
constructor(brand, name) {
this.brand = brand
this.name = name
}
show() {
console.log(`이 신발은 ${this.brand}의 ${this.name}입니다.`)
}
}
class Adidas extends Sneakers {
constructor(brand, name, size) {
super(brand, name)
this.size = size
}
}
let superstar = new Adidas('adidas', 'superstar', 280)
console.log(superstar.brand)
console.log(superstar.name)
console.log(superstar.size)
superstar.show()