자바스크립트 클래스 참조
자바스크립트 클래스
A class
는 함수 유형이지만 키워드
를 사용 function
하여 시작하는
대신 키워드를 사용 class
하고 속성은
constructor()
메서드 내부에 할당됩니다.
예시
Car 클래스를 만든 다음 Car 클래스를 기반으로 "mycar"라는 개체를 만듭니다.
class Car { // Create a class
constructor(brand) { // Class constructor
this.carname = brand;
// Class body/properties
}
}
mycar = new Car("Ford"); // Create an object of Car
class
클래스에 대한 튜토리얼은 JavaScript 클래스 튜토리얼 을 읽어보세요 .
클래스 메서드
Method | Description |
---|---|
constructor() | A special method for creating and initializing objects created within a class |
클래스 키워드
Keyword | Description |
---|---|
extends | Extends a class (inherit) |
static | Defines a static method for a class |
super | Refers to the parent class |