2
以下兩種繼承Javascript對象的方法有什麼區別嗎?用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