Skip to content

Instantly share code, notes, and snippets.

@joeljuca
Created April 27, 2017 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeljuca/c52e83d8cc2fff37a93013be48c20462 to your computer and use it in GitHub Desktop.
Save joeljuca/c52e83d8cc2fff37a93013be48c20462 to your computer and use it in GitHub Desktop.
Basics of prototype chaining and hierarchy
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