class ElementarySchoolStudent extends Student {
constructor(name, age, gender, school, afterClass) {
super(name, age, gender, school);
this.afterClass = afterClass;
}
get age() {
return this._age;
}
set age(value) {
// if (value < 8 || value > 12) {
// console.error("초등학생의 나이가 아니야!");
// }
this._age = value < 8 ? 8 : value;
}
greeting() {
super.greeting();
console.log(`반가워. 나는 ${this.school}에 다녀.`);
}
doAfterClass() {
console.log(`${this.name}는 방과후에 ${this.afterClass}를 해요.`);
}
}
오버라이딩
getter와 setter
사용자가 실수로 -1로 입력하면
방어적인 자세로 만들수잇게 하는것이 게터와 세터
get키워드를 이용해서 값을 리턴하고
set키워드를 이용해서 값을 설정
값을 설정해야하기 때문에 value를 받아와야 한다
새로운 밸류를 받으면 this.age를 벨류로 설정하게 된다
세터에서 마이너스 값을 주면 어떻하니?
값이 들어오면 프로포티의 값에 값을 직접 할당하는 것이 아니라 setter를 호출한다.
모든 JavaScript 객체는 프로토타입 객체를 가지고 있다.
let div = document.createElement("div");
console.log("div");
console.log(div.__proto__);
console.log(div.__proto__.__proto__);
console.log(div.__proto__.__proto__.__proto__);
console.log(div.__proto__.__proto__.__proto__.__proto__);
console.log(div.__proto__.__proto__.__proto__.__proto__.__proto__);
console.log(div.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__);
console.log(
div.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__.__proto__
);