Created
April 25, 2016 19:26
-
-
Save dnasca/5cbdcddcbd629dd06a19251aa3cc6f7f to your computer and use it in GitHub Desktop.
Classes in JS
This file contains hidden or 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(race) { | |
this.race = race; | |
} | |
} | |
class Cat extends Animal { | |
constructor(race) { | |
super(race); | |
} | |
say() { | |
console.log(this.race + ' says "Meow!"'); | |
} | |
} | |
class Dog extends Animal { | |
constructor(race) { | |
super(race); | |
} | |
say() { | |
console.log(this.race + ' says "Bark!"'); | |
} | |
} | |
var cat = new Cat('cheshire') | |
, dog = new Dog('bulldog') | |
; | |
cat.say(); | |
dog.say(); | |
console.log(cat instanceof Cat); | |
console.log(cat instanceof Dog); | |
console.log(cat instanceof Animal); | |
console.log(dog instanceof Animal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment