Skip to content

Instantly share code, notes, and snippets.

@quangnd
Created July 19, 2016 10:20
Show Gist options
  • Save quangnd/7d614b504c077ac9fc2571485aa7ec8f to your computer and use it in GitHub Desktop.
Save quangnd/7d614b504c077ac9fc2571485aa7ec8f to your computer and use it in GitHub Desktop.
Crate Prototypes with Classes
'use strict';
//New in ES6
class Animal {
constructor(voice){
this.voice = voice || "Grunt"
}
speak() {
console.log(this.voice)
}
}
class Cat extends Animal {
constructor(name,color) {
super("Meowww")
this.name = name
this.color = color
}
}
var fluffy = new Cat("Fluffy", "White")
fluffy.speak()
console.log(fluffy.__proto__.constructor.toString())
console.log(fluffy.__proto__.__proto__.constructor.toString())
//Copy and try at http://www.es6fiddle.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment