Created
February 5, 2015 20:37
-
-
Save raribeiro/3be2091cb9405126ea4d to your computer and use it in GitHub Desktop.
My simple model of Inheritance Pattern.
This file contains 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 Car(_name, _year) { | |
this.name = _name; | |
this.year = _year; | |
} | |
Car.prototype.carType = function () { | |
return "My car is a " + this.name + ", this year is " + this.year + "."; | |
}; | |
function CarModel(_model, _name, _year) { | |
Car.call(this, _name, _year); | |
this.model = _model; | |
} | |
CarModel.prototype.completeCar = function () { | |
return "My car is one " + this.model + ", type " + this.name + " and your year is " + this.year + "."; | |
}; | |
var car = new Car("BMW", 2015); | |
var completeCar = new CarModel("Galeardo", "BMW", 2015); | |
alert(car.carType()); | |
alert(completeCar.completeCar()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment