Prototype
Prototype : 객체의 원형
함수는 객체, 그러므로 생성자로 사용될 함수도 객체임
객체는 프로퍼티(property)를 가질 수 있는데 prototype이라는 프로퍼티는 그 용도가 약속되어 있는 특수한 프로퍼티임
1. Prototype Chain
prototype은 객체와 객체를 연결하는 체인의 역할 객체에 저장된 속성들을 생성자를 통해서 객체가 만들어질 때 그 객체에 연결
function Ultra(){}
Ultra.prototype.ultraProp = true;
function Super(){}
Super.prototype = new Ultra();
//*주의! Super.prototype = Ultra.prototype 으로하면 안됨
//부모관계인 Ultra.prototype의 값 또한 변경되기 때문
function Sub(){}
Sub.prototype = new Super(); //Super.prototype을 원형으로 하는 객체 생성
var o = new Sub(); //Sub.prototype을 원형으로 하는 객체 생성
console.log(o.ultraProp);
//true
Last updated
Was this helpful?