Class ?
그냥 쉽게 무언가를 만들기 위한 설계도라고 이해하자.
인스턴스를 만들기 위한 설계도이다.
Class 어떻게 만드나요?
class Shoes { // class는 ES6 이후 새로운 문법이다
constructor(brand, color) { // 생성자 함수
}
}
Constructor (생성자)
Class 속성 정의
class Shoes {
constructor(brand, color) {
this.brand = brand; // this는 Instance 객체를 의미한다.
this.color = color;
}
Class 메소드 정의
class Shoes {
constructor(brand, color) {
this.brand = brand;
this.color = color;
resell(){ // 메소드 정의
}
}
Instance ?
쉽게 설명하면 Class에 의해 만들어진 객체가 Instance 이고
일반 객체와 구분을 하기위해서 이렇게 부른다.
Instance 어떻게 만드나요?
let airJordan = new Shoes('nike','blacktoe');
let yeezyBoost = new Shoes('adidas','zebra');
Instance에서 사용 방법
airJordan.brand; // nike
airJordan.resell();