0

Im trying to call Person.showInfo() from inside Professor constructor, with its name and age as a parameters. Is it possible?. Please see the comment below thanks.

var Person = function(_name, _age) {
    this.name = _name;
    this.age = _age;
}

Person.prototype.showInfo = function() {
    console.log(this.name, this.age);
};

var Professor = function(_name, _age, _course) {
    Person.call(this, _name, _age);
    this.course = _course;
};

Professor.prototype = Object.create(Person.prototype);
Professor.prototype.constructor = Professor;

Professor.prototype.showInfo = function() {
    // How to call Person.showInfo() here ???
    // Person.prototype.showInfo() ...showing the Professor's name and age
    console.log(this.course);
};
vincent thorpe
  • 171
  • 1
  • 10

1 Answers1

0
Person.prototype.showInfo.call(this);

Simply call the function as it is, but change the context.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151