【发布时间】:2013-03-28 10:37:54
【问题描述】:
我正在研究Javascript中继承的概念,我正在看的教程使用了这段代码:
// define the Student class
function Student() {
// Call the parent constructor
Person.call(this);
}
// inherit Person
Student.prototype = new Person();
// correct the constructor pointer because it points to Person
Student.prototype.constructor = Student;
我的问题是,为什么必须同时调用父构造函数Person.call(this),并将Student 原型设置为等于新的Person 对象(即Student.prototype = new Person();)?
【问题讨论】: