프로토타입(Prototype)
__proto__ => 던더(Dunder) 게터
[[]] 대괄호 두개 => 숨겨진 객체
let o = {};
console.log(o.__proto__);
__proto__와 [[Prototype]]는 다름!
(__proto__은 [[prototype]]객체에 접근하기 위한 하나의 관문같은 것)
let o = {};
console.log(Object.getPrototypeOf(o));
게터를 통해서 접근하든 메서드를 통해서 접근하든 둘 다 결과는 같다.
//함수 선언식이든 표현식이든 상관없이 prototype을 갖는다.
function func1() {};
let func2 = function() {};
console.log(func1.prototype); //{constructor: func1}
console.log(func2.prototype); //{constructor: func2}
function User(name){
//자동으로 대입
//this = {}
//this.__proto__ = User.prototype //{ constructor: User}
this.name = name;
//return this;
}
※ prototype 객체에 공통 메서드를 정의하더라도 this의 값은 점(.) 앞 객체를 가리키므로 문제 없이 사용 가능하다.