Skip to content

Instantly share code, notes, and snippets.

@vasergen
Created July 20, 2016 09:33
Show Gist options
  • Save vasergen/3ece3320f067e40ec2651591dba6c39e to your computer and use it in GitHub Desktop.
Save vasergen/3ece3320f067e40ec2651591dba6c39e to your computer and use it in GitHub Desktop.
//Prototype Pattern
function Animal(name) {
this.name = name
}
Animal.prototype.say = function() {
console.log(`I am ${this.name}`)
}
function Rabbit(name) {
Animal.call(this, name)
}
Rabbit.prototype = Object.create(Animal.prototype)
Rabbit.prototype.skip = function() {
console.log(this.name + ': I skip')
}
let r1 = new Rabbit('r1')
r1.say()
r1.skip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment