OOP 간단 정리
클래스 기반 언어
프로토타입 기반 언어
생성자 함수와 인스턴스 생성
// 생성자 함수(Constructor)
function Person(name) {
// 프로퍼티
this.name = name;
// 메소드
this.setName = function(name) {
this.name = name;
};
// 메소드
this.getName = function() {
return this.name;
};
}
var me = new Person('Lee');
var you = new Person('Kim');
var him = new Person('Choi');
console.log(me); // Person { name: 'Lee', setName: [Function], getName: [Function] }
console.log(you); // Person { name: 'Kim', setName: [Function], getName: [Function] }
console.log(him); // Person { name: 'Choi', setName: [Function], getName: [Function] }프로토타입 체인으로 해결하자.
상속
클래스 기반 언어의 상속 방식 흉내내기
프로토타입 패턴 상속
Object.create
Summary
qna
Last updated
Was this helpful?