Last active
June 11, 2018 16:10
-
-
Save neerajkumar/09af1e6eb361280baec71dd1bd73fa68 to your computer and use it in GitHub Desktop.
ES5 Inheritence Example - Javascript Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Vehicle(speed) { | |
this.speed = speed; | |
} | |
function Car(vehicle_type, speed) { | |
// this._super.call(this, speed); | |
this.speed = speed; | |
this.vehicle_type = vehicle_type; | |
} | |
// Car.prototype._super = Vehicle; | |
function RedCar(color, vehicle_type, speed) { | |
this._super.call(this, vehicle_type, speed); | |
this.color = color; | |
} | |
RedCar.prototype._super = Car; | |
RedCar.prototype.desc = function() { | |
console.log("The Vehicle is of type " + this.vehicle_type + " and its color is " + this.color); | |
} | |
RedCar.prototype.drive = function() { | |
console.log("Vehicle speed is " + this.speed + " km per hour"); | |
} | |
RedCar.prototype.driveFast = function() { | |
if (this.speed > 100) { | |
console.log("Vehicle is driving very fast"); | |
} else { | |
console.log("Vehicle is driving normally"); | |
} | |
} | |
red_car = new RedCar('Red', 'Car', 105); | |
red_car.desc(); | |
red_car.drive(); | |
red_car.driveFast(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment