Prototype, constructor(), super()

wonkeunC·2021년 4월 29일
0

JavaScript

목록 보기
7/15
post-thumbnail

https://poiemaweb.com/js-prototype



medium.com/@bluesh55/javascript-prototype-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-f8e67c286b67


.

constructor

Person 객체를 만들면 Person’s prototype도 자동적으로 생성이되는데 이는 Person.prototype을 가르킨다.Person’s prototype객체도 자신이 Person의 소속이라는 것을 표시하기 위해서 어딘가에 기록을 해놔야 한다.

그 기록은 constructor이라는 property를 만들고 이는 Person을 가르킨다. ( 이렇게 서로간에 상호참조를 하고 있다.)

Person.prototype.sum = function( ) { }
: 객체를 찍어내는 공장인 Person이라는 constructor function() 을 만든 것이다.

이 객체는 👇

최종적으로

  • var lee = new Person( "lee" , 10, 10 ) 을 추가하면



Super()

super () : 부모 class 를 불러서 부모 class 한테 일을 시키고 부모가 하지 못하는 일은 나만 하도록 .

super() 없이 추가하는 방법.

super () : super에 () 괄호가 붙으면 이 의미는 부모 class의 생성자라는 의미이다.

profile
개발자로 일어서는 일기

1개의 댓글

comment-user-thumbnail
2021년 4월 30일

정리👍🏻👍🏻👍🏻

답글 달기