프로퍼티 어트리뷰트에 대해 설명을 잘 해주셨다.(정말 새로 배운 내용이었다.)
자바스크립트 엔진은 프로퍼티를 생성할 때 프로퍼티의 상태를 나타내는 프로퍼티 어트리뷰트를 기본값으로 자동 정의한다.
→ Object.getOwnPropertyDescriptor 메서드를 사용하여 간접적으로 확인할 수 있다.
→ 데이터 프로퍼티는 모두 true로 초기화가 된다.
getter함수와 setter함수에 대해 설명을 잘 해주셨다.
const person = {
firstName: 'Kae',
lastName: 'Okamura',
get fullName() {
return `${this.firstName} ${this.lastName}`;
},
set fullName(name) {
[this.firstName, this.lastName] = name.split(' ');
}
};
person.lastName = 'Kim'; // 'Kae Kim'
console.log(person.fullName)
객체 변경을 방지할 수 있는 메소드에 대해 새로 배웠다.(이런 게 있는 줄 몰랐다... 😨)
정리를 한번 해봤다.🔻
const person = {name: 'Lee'};
Object.preventExtensions(person);
person.age = 10; // 추가 못함
console.log(person) // {name: "Lee"}
delete person.name; // 삭제는 가능
console.log(person) // {}
const person = {name: 'Lee'};
Object.seal(person);
person.age = 10; // 추가 못함
console.log(person) // {name: "Lee"}
delete person.name; // 삭제도 못함
console.log(person) // {name: "Lee"}
person.name = 'Kim';
console.log(person); // {name: "Kim"} 프로퍼티 값 갱신(변경)은 가능!
const person = {name: 'Lee'};
Object.freeze(person);
person.age = 10; // 추가 못함
console.log(person) // {name: "Lee"}
delete person.name; // 삭제도 못함
console.log(person) // {name: "Lee"}
person.name = 'Kim';
console.log(person); // {name: "Lee"}
생성자 함수가 어떤 것이고 일반 함수가 어떤 것인지 정확하게 설명을 해주셨다.
그동안 그냥 모르고 쓰고 있었는데 덕분에 잘 이해가 되었다.
function Circle(radius){
this.radius = radius;
this.getDiameter = function(){
return 2 * this.radius;
};
};
const circle1 = new Circle(5) // 생성자 함수
const circle2 = new Circle(10) // 생성자 함수
const circle3 = Circle(15) // 일반 함수
생성자 함구의 인스턴스 생성 과정에 대해 그림까지 그리면서 열심히 설명을 해주셨다.
이미 알고 있는 부분이었지만 설명을 들으니까 정리도 되고 좋았다.

마지막으로 재영님이 질문해주신 var hoisting에 대해 추가 설명을 하고자 한다.