Last active
August 29, 2015 14:06
-
-
Save mbrowne/cb437f4573fd9b912833 to your computer and use it in GitHub Desktop.
Pure prototypal inheritance in Javascript
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
var Animal = { | |
init: function(name) { | |
this.name = name || null; | |
} | |
} | |
var Cat = Object.create(Animal); | |
Cat.meow = function() { | |
console.log('meow'); | |
} | |
var garfield = Object.create(Cat); | |
garfield.init('Garfield'); | |
garfield.meow(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment