Created
July 19, 2016 10:20
-
-
Save quangnd/7d614b504c077ac9fc2571485aa7ec8f to your computer and use it in GitHub Desktop.
Crate Prototypes with Classes
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
'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