OOP JS

Human Asian inheritance problem

by Ritesh Pandey

JavaScript

/*
    1. Create a class Human.
      a. Constructor of Human Takes in three Params: ssn , firstName , lastName
      b. Make ssn a private property of Human.
      c. Expose a getter methods getSSN , getFirstName & getLastName.
      d. Expose a setter methods setFirstName & setLastName.
      e. Expose a method getFullName

    2. Create a class Asian derived from Human.
       a. Constructor of Human Takes in three Params: ssn , firstName , lastName , country.
       b. Expose a method getCountry.
*/

function Human(ssn, firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    this.getSSN = function() {
        return ssn;
    }
};

Human.prototype.getFirstName = function () {
    return this.firstName;
};

Human.prototype.getLastName = function () {
    return this.lastName;
};

Human.prototype.getFullName = function () {
    return this.firstName + this.lastName;
};

Human.prototype.setFirstName = function (firstName) {
    this.firstName = firstName;
};

Human.prototype.setLastName = function (lastName) {
    this.lastName = lastName;
};

function Asian(ssn, firstName, lastName, country) {
    Human.call(this, ssn, firstName, lastName);
    this.country = country;
}

Asian.prototype = Human.prototype;

Asian.prototype.getCountry = function () {
    return this.country;
};

var h1 = new Human(123, 'aa', 'bb');
var a1 = new Asian(123, 'Ritesh', 'Pandey', 'India');