I was wrong. The class Employee constructor, call the constructor of the class Person,
using the call() method. That is how you call any base method that has been overridden.
function Person(lastName, firstName){ this.LastName = lastName; this.FirstName = firstName; this.getFullName = function(){ return this.LastName + " " + this.FirstName; } } function Employee(firstName, lastName , company){ // Call the constructor of the base class Person.call(this, firstName, lastName); this.Company = company; this.getFullName = function(){ return Employee.prototype.getFullName.call(this) + " " + this.Company; } } Employee.prototype = new Person(); var fred = new Employee("Torres", "Frederic", "ACompany" ); console.log(fred.getFullName());
No comments:
Post a Comment