문서의 이전 판입니다!
ES6라고도 하는 ECMAScript 2015는 JavaScript 클래스를 도입했습니다.
JavaScript 클래스는 JavaScript 오브젝트를위한 템플릿(templates)입니다.
=====JavaScript Class Syntax
class
키워드를 사용하여 클래스를 만듭니다.
항상 constructor()
라는 메서드를 추가합니다.
class ClassName { constructor() { ... } }
class Car { constructor(name, year) { this.name = name; this.year = year; { }
위의 예에서는 “Car”라는 클래스를 만듭니다.
클래스에는 “이름(name)“과 “연도(year)“라는 두 가지 초기 속성(initial properties)이 있습니다.
JavaScript 클래스는 오브젝트가 아닙니다.
JavaScript 오브젝트를 위한 템플릿(template)입니다.
클래스가 있으면, 클래스를 사용하여 오브젝트를 만들 수 있습니다.