Last active
August 14, 2018 05:21
-
-
Save prograhammer/83f124edaeb1ccfa3cfb22831110ff0d to your computer and use it in GitHub Desktop.
ES6 Class
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
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