( Daliy / TIL 03.04) prototype

Seung Ho Yoon·2021년 3월 7일
0

I studied this today

  • prototype
  • _.proto__

prototype

Prototype은 자바스크립트의 내장 객체이다.

constructor 가 담긴 object이며, Prototype의 상위 객체는 큰 Object이다 그래서 속성과 메소드를 담을 수 있다.

es5에서 클래스를 상속하려면 object.create를 이용해서 부모관계를 부모관계를 형성해 준다.

//es5
bee.prototype = object.create(Grub.prototype);
bee.prototype.constructor = bee;

//es6
contructor (name) {
  super(name);
}

bee instanceof Grub  === true;
상속관계를 확인 할 수 있음.

._proto__

._proto__은 Prototype의 체인이다 즉, prototype의 주소를 가지고 있다.

constuctor가 담긴 object이며, Prototype의 주소를 가지고 있음.

steve._proto_ === Human.prototype === true
steve._proto_._proto_ === Object === true

profile
Frontend Developer

0개의 댓글