Created
October 31, 2014 06:14
-
-
Save TessMyers/31aaf38de1de4b9be40a to your computer and use it in GitHub Desktop.
Pseudoclassical instantiation
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
// This function does not return anything, but instead creates a new instance of an object with | |
// the given attributes when the "new" keyword is used. | |
var Cat = function(){ | |
this.stomach = []; | |
}; | |
// adds methods to the prototype for this new cat object | |
Cat.prototype.meow = function(){ | |
console.log("MEOWPURR"); | |
}; | |
Cat.prototype.eat = function(food){ | |
this.stomach.push(food); | |
}; | |
// make that kitty | |
var kitty = new Cat(); | |
kitty.meow(); // "MEOWPURR" | |
kitty.eat('tiny helpless birds'); | |
console.log(kitty.stomach) // ["tiny helpless birds"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment