prototype chain

Purple·2021년 10월 15일
0

TIL

목록 보기
33/73

예시 코드

class Human{
    constructor(name,age){
        this.name=name;
        this.age=age;
    }   
    sleep(){ return `${this.name}이(가) 잠을 잡니다.`}
} // Human class를 만들었다.

class Student extends Human{
    constructor(name,age,grade){// subclass에 constructor가 있다면
        super(name,age)//this를 사용하기전에 가장먼저 super()를 호출해야한다.
        this.grade=grade; 
    }
    study(){
    return `${this.name}이(가) 공부를 합니다.`}
}// extends를 이용하여 Human클래스를 상속



profile
다시 보면, 더 많은 것들이 보인다.

0개의 댓글