JavaScript:Class
lastmod 2022-12-08created 2022-12-083 edits
How to create a Class in JavaScript.
Literal-style class
Function-style class
function 클래스이름() {
this.프로퍼티1 = 초기값;
this.프로퍼티2 = 초기값;
this.메서드1 = function() {
// ...
}
this.메서드2 = function() {
// ...
}
}
Prototype-style class
function 클래스이름() {
this.프로퍼티1 = 초기값;
this.프로퍼티2 = 초기값;
}
클래스이름.prototype.메서드1 = function() {
// ...
}
클래스이름.prototype.메서드2 = function() {
// ...
}