function Person(name, age) { this.name = name; this.age = age; this.friends = ["kim", "lee", "park"]; } Person.prototype.sayName = function() { document.write(this.name + "<br>"); } function Student(name, age, major) { Person.call(this, name, age); // 프로퍼티 상속 this.major = major; } // 메서드 상속 Student.prototype = new Person(); Student.prototype.consturctor = Student; // 생성자를 Student로 변경 // 메서드 추가 Student.prototype.sayMajor = function() { document.write(this.major + "<br>"); } var student1 = new Student("nam", 33, "컴퓨터과학과"); var student2 = new Student("sin", 27, "미디어영상학과"); // student2 출력 student1.sayName(); // nam student1.sayMajor(); //컴퓨터과학과 student1.friends.push("hong"); // student1.colsrs 에 hong 추가 document.write(student1.friends + "<br>"); // kim,lee,park,hong // student2 출력 student2.sayName(); // sin student2.sayMajor(); // 미디어영상학과 document.write(student2.friends + "<br>"); // kim,lee,park // 상속 확인 document.write(student1 instanceof Person); // true document.write("<br>") document.write(Student.prototype.isPrototypeOf(student1)); // true