Created
April 27, 2017 00:50
-
-
Save joeljuca/c52e83d8cc2fff37a93013be48c20462 to your computer and use it in GitHub Desktop.
Basics of prototype chaining and hierarchy
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
function Animal (animalName) { | |
this.name = animalName | |
} | |
Animal.prototype.walk = function () { | |
console.log('Walking around...') | |
} | |
function Cat (catName) { | |
Animal.call(this, catName) | |
this.type = 'cat' | |
} | |
Cat.prototype = new Animal() | |
Cat.prototype.scratch = function () { | |
console.log('Scratching your forniture...') | |
} | |
var meow = new Animal('Meow') | |
var shell = new Cat('Shell') | |
shell.walk() | |
shell.scratch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment