Sto studiando il concetto di ereditarietà in Javascript, e il tutorial sto guardando usa questo codice:Inheritance entro 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;
La mia domanda è, perché è necessario sia per chiamare il costruttore genitore , Person.call(this)
e impostare il prototipo Student
uguale a un nuovo oggetto Person
(ad esempio Student.prototype = new Person();
)?
http://stackoverflow.com/questions/892595/javascript-prototypal-inheritance?rq=1 –