Implement Inheritance

"is a" relationship ex: an apple is a fruit, an employee is a person, and a piano is an instrument.

by isogunro

JavaScript

var Vehicle = (function () {
    function Vehicle(year, make, model) {
         this.year = year;
         this.make = make;
         this.model = model;
}
Vehicle.prototype.getInfo = function() {
     return this.year + ' '+ this.make + ' '+this.model;   
};
Vehicle.prototype.startEngine = function() {
     return 'Vroom';   
};
return Vehicle;
})();

var v2 = new Vehicle(2015,'Jeep', 'Wrangler');
alert(v2.getInfo());
alert(v2.startEngine());

//Implement INHERITANCE
var Car = (function (parent) {
    Car.prototype = new Vehicle();
    Car.prototype.constructor = Car;
    function Car(year, make, model) {
         parent.call(this, year, make, model);
         this.wheelQuantity = 4;
    }
    Car.prototype.getInfo = function() {
        return 'Vehicle Type: Car '+ parent.prototype.getInfo.call(this);
    };
    return Car;
})(Vehicle);