Created
May 20, 2018 18:21
-
-
Save lopezm1/619b9344a0d7df3a21fa264d1efebedb to your computer and use it in GitHub Desktop.
js prototype
This file contains hidden or 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(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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function makeNoise() exists as a prototype across all Animal objects, ultimately saves memory