Skip to content

Instantly share code, notes, and snippets.

@quangnd
Created July 19, 2016 10:09
Show Gist options
  • Save quangnd/51ad48f729cdf1415d03f0a0d741e84a to your computer and use it in GitHub Desktop.
Save quangnd/51ad48f729cdf1415d03f0a0d741e84a to your computer and use it in GitHub Desktop.
Create Prototypes with Inheritance Chains
'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