상세 컨텐츠

본문 제목

[자바스크립트] 자바스크립트에서의 클래스의 이름

카테고리 없음

by esoesmio 2023. 5. 4. 21:15

본문

name이라는 변수가 따로 없어도 클래스 뒤에 붙은게 클래스 이름이다.

 

클래스에 이름이 없어면 변수 이름으로 한다.

 

// unnamed
let Rectangle = class {
    constructor(height, width) {
        this.height = height;
        this.width = width;
    }
};
console.log(Rectangle.name);
// 출력: "Rectangle"

// named
let Rectangle = class Rectangle2 {
    constructor(height, width) {
        this.height = height;
        this.width = width;
    }
};
console.log(Rectangle.name);
// 출력: "Rectangle2"

댓글 영역