티스토리 뷰
class Grandma{
constructor(name){
this.firstname = 'lee'
this.name = name
}
}
let Grandma1 = new Grandma('chaeyoung')
Grandma와 유사한 class를 만들고싶다.
=> 할머니의 속성을 그대로 물려받아서.
=> extends 사용
extends해서 만든 class는 this를 함부로 사용할수없다.
super()다음에 사용해야한다.
super : 부모 class의 constructor를 의미한다.
class Grandma{
constructor(name){
this.firstname = 'lee'
this.name = name
}
}
class Mother extends Grandma{
constructor(name){
super(name);
this.age = 50
}
}
let Mother1 = new Mother(); // <- 오브젝트 뽑기
'Javascript > [JS&Node] 객체 지향' 카테고리의 다른 글
[javascript]객체지향 프로그래밍과 함수형프로그래밍 (0) | 2022.05.28 |
---|---|
JSON이란?? (0) | 2021.11.21 |
Object 생성기계인 constructor (0) | 2021.11.20 |
Prototype 프로토타입 : 상속....상속...상속!! (0) | 2021.11.08 |
객체지향프로그래밍 (0) | 2021.11.08 |