Created
July 19, 2016 10:09
-
-
Save quangnd/51ad48f729cdf1415d03f0a0d741e84a to your computer and use it in GitHub Desktop.
Create Prototypes with Inheritance Chains
This file contains 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'; | |
function Animal(voice) { | |
this.voice = voice || "grunt" | |
} | |
Animal.prototype.speak = function() { | |
display(this.voice); | |
} | |
function Cat(name, color) { | |
Animal.call(this, 'Meow') | |
this.name = name | |
this.color = color | |
} | |
Cat.prototype = Object.create(Animal.prototype) | |
Cat.prototype.constructor = Cat | |
var fluffy = new Cat("Fluffy", "White") | |
fluffy.speak(); | |
console.log(fluffy.__proto__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment