Я изучаю понятие наследования в JavaScript, и учебник я смотрю на использует этот код:Наследование в 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();
)?
http://stackoverflow.com/questions/892595/javascript-prototypal-inheritance?rq=1 –