Skip to content

Instantly share code, notes, and snippets.

@TessMyers
Created October 31, 2014 06:14
Show Gist options
  • Save TessMyers/31aaf38de1de4b9be40a to your computer and use it in GitHub Desktop.
Save TessMyers/31aaf38de1de4b9be40a to your computer and use it in GitHub Desktop.

Revisions

  1. TessMyers created this gist Oct 31, 2014.
    21 changes: 21 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    // 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"]