Skip to content

Instantly share code, notes, and snippets.

@saxbophone
Created November 7, 2015 17:42
Show Gist options
  • Save saxbophone/66ad91a3a49226035459 to your computer and use it in GitHub Desktop.
Save saxbophone/66ad91a3a49226035459 to your computer and use it in GitHub Desktop.
Trying out ES6 classes, I think I made a mistake somewhere...
class Animal {
constructor(name="Unnamed", age=0, height=0) {
this.name = name;
this.age = age;
this.height = height;
}
describe() {
return `Species:\t${this.constructor.name}\nName:\t${this.name}\nAge:\t${this.age}\nHeight:\t${this.height}`;
}
}
class Mammal extends Animal {
constructor(name="Unnamed", age=0, height=0, hasFur=true) {
super(name=name, age=age, height=height);
this.hasFur = hasFur;
this.warm_blooded = true;
}
}
class Cat extends Mammal {
constructor(name="Unnamed", age=0, height=0) {
super(name=name, age=age, height=height, hasFur=true);
}
}
class Whale extends Mammal {
constructor(name="Unnamed", age=0, height=0) {
super(name=name, age=age, height=height, hasFur=false);
}
}
class Human extends Mammal {
constructor(name="Unnamed", age=0, height=0) {
super(name=name, age=age, height=height, hasFur=false);
}
}
let josh = new Human(name="Josh", age=19, height=192);
console.log(josh.describe());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment