Skip to content

Instantly share code, notes, and snippets.

@ow
Forked from csarrazi/es6.js
Created March 7, 2016 13:38
Show Gist options
  • Save ow/f2afc7fa23c0f0592082 to your computer and use it in GitHub Desktop.
Save ow/f2afc7fa23c0f0592082 to your computer and use it in GitHub Desktop.
ES6 classes
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);
@gabrielPeart
Copy link

Nice example. Thanks for sharing. I would suggest to refactor the property "race" and rename it to "breed"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment