Skip to content

Instantly share code, notes, and snippets.

@lopezm1
Created May 20, 2018 18:21
Show Gist options
  • Save lopezm1/619b9344a0d7df3a21fa264d1efebedb to your computer and use it in GitHub Desktop.
Save lopezm1/619b9344a0d7df3a21fa264d1efebedb to your computer and use it in GitHub Desktop.
js prototype
function Animal(animal, noise) {
this.noise = noise;
this.animal = animal;
}
Animal.prototype.makeNoise = function() {
console.log('I\'m a ' + this.animal + ' - ' + this.noise)
}
var dog = new Animal("dog", "woof");
var dog2 = new Animal("dog", "woof");
@lopezm1
Copy link
Author

lopezm1 commented May 20, 2018

function makeNoise() exists as a prototype across all Animal objects, ultimately saves memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment