티스토리 뷰

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(); // <- 오브젝트 뽑기

 

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG more
«   2025/07   »
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
글 보관함