오늘도 여전히 JS 기본을 공부했다.
함수
function a (b) {
console.log(b)
};
새로운 방식인 Arrow Fuction이라는 것도 있다.
const a = (b) => {
console.log(b)
};
다른 언어도 그런지 모르겠지만 함수안에 함수를 또 할수있는게 너무 매력적이였다.
클래스
class car{
constructor(name, price, brand) {
this.name = name
this.price = price
this.brand = brand
}
}
const myCar = new car('sonata', 2000, 'hyundai')
클래스 안에 함수도 넣어줄수있다.
class car {
constructor(){...}
printInfo() {
console.log(`차종: ${this.name}, 가격: ${this.price}원`)
}
}
const myCar = new car('sonata', 2000, 'hyundai')
myCar.printInfo()
클래스를 다른 클래스와 연결도 할수있다.
class bmw enxtends car {
constructor (color){
super(); // super로 연결해준다
this.color = color
}
printInfo() {
super.printInfo(); // car 클래스에 있는 함수도 가져와서 사용가능
}
}