Car 함수선언시 Car에 대한 Prototype이 생성된다.
Car 내부 메소드 접근 및 추가시 아래와 같이 prototype을 통해 접근하거나 새로 선언해준다.
별도의 변수를 통해 Car prototype에 접근해야한다면 new를 붙여 접근을 해야하며, 이때 a는 별도의 prototype을 가지지않는다.
a의 prototype 접근이 완료되었다면, 이후엔 기존 메소드처럼 사용할 수 있다.
function Car(a, b){
this.name = a;
this.color = b;
}
Car.prototype.merge = function(){
console.log(this.name + " " + this.color);
}
console.log(Car("Hi", "world"));
a = new Car("hello", "world");
a.merge();
https://poiemaweb.com/js-prototype
코드에 대한 이해가 우선이다. sugar syntax보다는 sugar logic!