JavaScript는 프로토타입을 사용한 상속을 사용한다.
// 기본적인 예제
function Vacation(destination, length) {
this.destination = destination;
this.length = length;
}
Vacation.prototype.print = function() {
console.log(this.destination + "은(는)" + this.length + "일 걸립니다.")
};
const maui = new Vacation("마우이", 7);
maui.print();
class Vacation {
constructor(destination, length) {
this.destination = destination;
this.length = length;
}
print() {
console.log(` ${this.destination} 은(는) ${this.length} 일 걸립니다.`);
}
}
클래스의 첫 글자는 대문자.
'Language > JavaScript' 카테고리의 다른 글
| JavaScript for React 2 (1) | 2023.01.08 |
|---|---|
| JavaScript for React 1 (1) | 2023.01.05 |