Skip to content

Instantly share code, notes, and snippets.

@raribeiro
Created February 5, 2015 20:37
Show Gist options
  • Save raribeiro/3be2091cb9405126ea4d to your computer and use it in GitHub Desktop.
Save raribeiro/3be2091cb9405126ea4d to your computer and use it in GitHub Desktop.
My simple model of Inheritance Pattern.
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