객체 지향 프로그래밍이란?
하나의 모델이 되는 청사진(설계도)을 만들고(class), 이를 바탕으로 한 객체(object)를 만드는(instance) 프로그래밍 패턴
클래스에 속성과 메소드 정의, 인스턴스에서 이용
클래스: 속성의 정의
클래스: 메서드의 정의
function Student(name, age, gender){} // 속성 정의
Student.prototype.study = function() {} // 메서드 정의
class Student {
constructor(name, age, gender){} // 속성 정의
study(){} // 메서드 정의
}
class Car {
constructor(brand, name, color){
this.brand = brand;
this.name = name;
this.color = color;
}
drive() {
console.log(this.name + '가 운전을 시작합니다');
}
} // ES6 방식으로 작성해 본 Car 클래스