2
Javascript에서 오브젝트를 상속하는 다음 두 가지 메소드 간에는 어떤 차이가 있습니까?자바 스크립트에서 오브젝트를 상속하는 두 가지 다른 (?) 메소드
function Person(name) {
this.name = name;
}
function Student(name, id) {
Person.call(this, name);
this.id = id;
}
방법 1 :
Student.prototype.__proto__ = Person.prototype;
방법 2 : 특정 패턴에 의해 객체의 생성 외에
Student.prototype = new Person;
Student.prototype.constructor = Student;
'constructor' 속성을 설정하는 것이 어떤 용도로든 생각하지 않습니다. – user123444555621