Skip to content

Instantly share code, notes, and snippets.

@prograhammer
Last active August 14, 2018 05:21
Show Gist options
  • Save prograhammer/83f124edaeb1ccfa3cfb22831110ff0d to your computer and use it in GitHub Desktop.
Save prograhammer/83f124edaeb1ccfa3cfb22831110ff0d to your computer and use it in GitHub Desktop.
ES6 Class
class Auto {
constructor(data) {
this.make = data.make;
this.model = data.model;
this.year = data.year;
this.price = data.price;
}
getDetails() {
return `${this.year} ${this.make} ${this.model}`;
}
}
class Car extends Auto {
constructor(data) {
super(data);
this.isElectric = data.isElectric;
this.isHatchback = data.isHatchback;
}
getDetails() {
return `${super.getDetails()} Electric: ${this.isElectric} Hatchback: ${this.isHatchback}`;
}
}
var car = new Car({
make: 'Chevy',
model: 'Malibu',
price: 30000,
year: 2014,
isElectric: false,
isHatchback: false
});
var div = document.getElementById('output');
div.innerHTML = car.getDetails();
// div.innerHTML = car.make;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment