16장
•
객체 변경 방지 메서드 3가지 비교
메서드 | 추가 | 삭제 | 읽기 | 쓰기 | 프로퍼티 어트리뷰트 재정의 |
Object.preventExtensions | x | o | o | o | o |
Object.seal | x | x | o | o | x |
Object.freeze | x | x | o | x | x |
◦
seal은 읽기와 쓰기만 가능
◦
freeze는 읽기만 가능(불변 객체)
•
__proto__와 prototype 프로퍼티
◦
__proto__는 인스턴스에서 프로토타입 객체에 접근하기 위한 프로퍼티.
◦
prototype은 생성자 함수 또는 클래스에서 프로토타입 객체에 접근하기 위한 프로퍼티
◦
둘은 동일한 참조를 갖는다.
17장
생성자 함수
19장
Q. 빈칸에 들어갈 프로퍼티는?
객체(인스터스)는 (a)를 통해 자신의 [[prototype]] 내부 슬롯이 가리키는 프로토타입에 간접 접근
프로토타입은 (b)를 통해 생성자 함수에 접근
생성자 함수는 (c)를 통해 프로토타입에 접근
Q. True or False
function Person(name){
this.name = name;
this.getName = function () {
return this.name;
}
}
Person.prototype.sayHi = function () {
console.log('hi', this.name);
}
const person111 = new Person('lee');
const person222 = new Person('lee');
console.log(person111.getName === person222.getName) // (a)
console.log(person111.constructor === Object) // (b)
console.log(Person.prototype.hasOwnProperty()) // (c)
const me = new Person('kim');
const parent = {};
Object.setPrototypeOf(me, parent);
console.log(Person.prototype); // (d)
console.log(me.constructor === Object) // (e)
JavaScript
복사
const obj = Object.create(null);
console.log(obj.__proto__); //
JavaScript
복사
22장
각각의 this가 가르키는 대상은?
function f1() {console.log(this)};
const f2 = function() {console.log(this)};
const obj1 = {
f3() {console.log(this)}
}
const F4 = function() {
this.printThis = function() {
console.log(this);
}
}
f1(); //(a)
f2(); //(b)
obj1.f3(); //(c)
const instance = new F4();
instance.printThis(); //(d)
const { printThis }= instance;
printThis(); //(e)
JavaScript
복사
strict 모드에서 undefined