Prototype과 Class

심우진·2022년 4월 9일
0
let extendClass = (function () {
  function Bridge() {}
  return function (Parent, Child) {
    Bridge.prototype = Parent.prototype;
    Child.prototype = new Bridge();
    Child.prototype.constructor = Child;
    Child.prototype.superClass = 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;
};

function Employee(name, age, position) {
  this.superClass(name, age);
  this.position = position || "직책모름";
}
extendClass(Person, Employee);

Employee.prototype.getPosition = function () {
  return this.position;
};

let roy = new Employee("로이", 30, "CEO");
console.dir(roy);

생성자 - 프로토타입
  |    /
인스턴스(프로토)
프로토타입에 접근할때는 __proto__ , ObjectgetPrototypeOf()

0개의 댓글

관련 채용 정보