Skip to content

Instantly share code, notes, and snippets.

@Lin4ipsum
Created June 30, 2012 16:10
Show Gist options
  • Save Lin4ipsum/3024410 to your computer and use it in GitHub Desktop.
Save Lin4ipsum/3024410 to your computer and use it in GitHub Desktop.
Rabbit Constructor in JS
// first we can make the instructor
function Rabbit(adjective) {
this.adjective = adjective;
this.describeMyself = function() {
console.log("I am a " + this.adjective + " rabbit");
};
}
// now we can easily make all of our rabbits
var rabbit1 = new Rabbit("fluffy");
var rabbit2 = new Rabbit("happy");
var rabbit3 = new Rabbit("sleepy");
rabbit1.describeMyself();
rabbit2.describeMyself();
rabbit3.describeMyself();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment