Created
November 7, 2015 17:42
-
-
Save saxbophone/66ad91a3a49226035459 to your computer and use it in GitHub Desktop.
Trying out ES6 classes, I think I made a mistake somewhere...
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 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