
ProtoType 설명 여기서 잠깐 써뒀지만, 이건 다소 구식이라고 한다.
Modern Prototype
Object.create(proto, [description]);
Object.getPrototypeOf(obj);
Object.setPrototypeOf(obj, proto);
1번 예시
let animal = {
eats: true
};
let rabbit = Object.create(animal);
이제 rabbit의 [[Prototype]]은 animal이다.
2번 예시
let animal = {
eats: true
};
let rabbit = Object.create(animal);
alert(Object.getPropertyOf(rabbit) == animal) // true
[[Propertype]]을 서로 비교해봐도 알 수 있다.
3번 예시
let animal = {
eats: true
};
let rabbit = Object.create(animal);
Object.setPropertyOf(rabbit, {})
이제 rabbit의 property는 빈 객체이다.