객체지향 프로그래밍은 모델로써의 '청사진'을 생성하여,
그 청사진을 바탕으로 한 객체를 만드는 패턴을 말함.
==> 여기서 청사진: class
==> 청사진을 바탕으로 생성된 객체 : instance 라고 용어를 지정
키워드 new
일반 변수선언과 같다. 단, instance는 new 를 붙여서 만든다.
==>let avante = new Car ('bmw', 'mini', 'white');
각 isntance는 클래스의 고유한 속성과 메소드를 가지게 됨.
function Car (brand, name, color){
this.brand = brand;
this.name = name;
this.color = color;
}
Car.prototype.refuel = function(){
//메소드 : ${this.name}에 연료를 공급합니다.
}
class Car{
constructor(brand, name, color){
this.brand = brand;
this.name = name;
this.color = color;
}
refuel() {
//메소드 : ${this.name}에 연료를 공급합니다.
}
}
let avante = new Car ('bmw', mini', 'white');
mini.brand; //bmw
mini.refuel(); //미니에 연료를 공급합니다.
let arr = new Array('a','b','c');
arr.length// 3
arr.push('course');
이런 형태로로 사용가능함.
class Teacher extends Person {
constructor(first, last, age, gender, interests, subject, grade) {
super(first, last, age, gender, interests);
// subject and grade are specific to Teacher
this.subject = subject;
this.grade = grade;
}
}
////////////////////////////////////////////////
**extends **super()
**const Bee = require('./Bee'); //물론 상위 클래스를 불러와야함(상속의경우)
super()연산자를 사용해주면 코드를 읽기 수월함.
이는, 상위클래스의 생성자를 호출하여 super()의 매개변수를 통해 상위 클래스의 멤버를
상속받을 수 있는 코드임.
상속
div 엘리먼트의 클래스 모식도