•
클래스는 어떤 공통된 속성이나 기능을 정의한 추상적인 개념이고,
이 클래스에 속한 객체를 인스턴스라 한다.
•
클래스에는 인스턴스에서는 직접 접근할 수 없는 클래스 자체에서만 접근 가능한 스태틱 멤버와,
인스턴스에서 직접 활용할 수 있는 프로토타입 메서드가 있다.
상속
//상속 구현
var extendClass = (function() {
function Bridge(){}
return function(Parent, Child) {
Bridge.prototype = Parent.prototype;
Child.prototype = new Bridge();
Child.prototype.constructor = Child;
Child.prototype.superClass = Parent;
}
})();
//Parent
function Person(name, age) {
this.name = name || '이름없음';
this.age = age || '나이모름';
}
Person.prototype.getName = function() {
return this.name;
}
Person.prototype.getAge = function() {
return this.age;
}
//Child
function Employee(name, age, position) {
this.superClass(name, age);
this.position = position || '직책모름';
}
extendClass(Person, Employee);
Employee.prototype.getPosition = function() {
return this.position;
}
JavaScript
복사