안녕세계

[JavaScript] Inheritance Mechanism (상속 메커니즘) 본문

[JavaScript] Inheritance Mechanism (상속 메커니즘)

Junhong Kim 2016. 7. 18. 20:21
728x90
반응형

 

 기존연결 ㅡ 
 끊은연결 ㅡ 
새로연결 

 

[inheritance.js]

function Parent(){}

function Child(){

    this.superconstructor(); // Parent() scope 생성
}
Child.prototype = new Parent();

Child.prototype.constructor = Child;

Child.prototype.superconstructor = Parent;

 

var obj = new Child();

 

[자바스크립트 상속 메커니즘]

1) 모든 함수는 Function 객체의 prototype 멤버를 상속
2) 
모든 함수의 prototype 객체는 Object 객체의 prototype 객체를 상속
3) 
모든 생성자 함수의 객체는 object 객체의 prototype 객체를 상속

 

728x90
반응형

'Language > JavaScript' 카테고리의 다른 글

[JavaScript] Date format  (0) 2017.04.12
[JavaScript] Closure Concept (클로저 개념)  (2) 2017.04.02
Comments