class Person {
constructor(first, last, age, gender, interests) {
this.name = {
first,
last
};
this.age = age;
this.gender = gender;
this.interests = interests;
}
greeting() {
console.log(`Hi! I'm ${this.name.first}`);
};
farewell() {
console.log(`${this.name.first} has left the building. Bye for now!`);
};
}
// Person을 class 문법으로 상속받아 Teacher 클래스 만들기 => 하위 클래스를 생성
// 생성자함수 안에서 첫번째로 super 키워드를 사용해서 상위 클래스 생성자를 호출하여 매개변수를 통해 상위 클래스 멤버를 상속받을 수 있음
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;
}
}
document.createElement('div')
로 생성된 div
엘리먼트는, HTMLDivElement라는 클래스의 인스턴스임
// 인스턴스의 접근자 프로퍼티인 __proto__를 이용해서 부모 클래스의 프로토타입, 부모의 부모 클래스의 프로토 타입을 탐색할 수 있음
let div = document.createElement('div');
div.__proto__
div.__proto__.__proto__
div.__proto__.__proto__.__proto__
div.__proto__.__proto__.__proto__.__proto__
div.__proto__.__proto__.__proto__.__proto__.__proto__
div.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__
div.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__
다형성의 핵심 단어 오버로딩
.prototype 은 클래스에서 프로토타입에 접근할 때
__proto__ 는 인스턴스에서 프로토타입에 접근할 때
왜 메서드일까? 객체 안에 있는 함수
→ 프로토타입 === 원형객체 ⇒ 원형객체 안에 있으므로 메서드라고 함