Skip to content

Instantly share code, notes, and snippets.

@ow
Forked from csarrazi/es6.js
Created Mar 7, 2016
Embed
What would you like to do?
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

gabrielPeart commented Mar 9, 2016

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