Skip to content

Instantly share code, notes, and snippets.

Last active Jun 8, 2018
What would you like to do?
ES6 constructors
//Simple implementation of a class using a the ES6 defined constructor function, showing inheritance
//using Vehicle Class to inherit property from
class Vehicle {
this._color = color;
//Car inherits from Vehicle class
class Car extends Vehicle{
constructor(color,make, model, year){
//super must be implemented before the child class properties.
this._make = make;
this._model = model;
this._year = year;
//using a get to return this._ values with get keyword method.
get make(){
return this._make.toUpperCase();
get model(){
return this._model
get year (){
return this._year;
set year(year){
this._year = year;
car = new Car("Red","Ford", "F-150", 1999);
car.model = "F-250";
console.log(car.model); //do to the set method not being used car.model == 'F-150'
car.year = 2018;
console.log(car.year)//2018, it worked, that old 99 was beat out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment