Skip to content

Instantly share code, notes, and snippets.

@le717
Created March 1, 2015 04:16
Show Gist options
  • Save le717/bf7685551a9e523883e7 to your computer and use it in GitHub Desktop.
Save le717/bf7685551a9e523883e7 to your computer and use it in GitHub Desktop.
function Rabbit() {
this.color = "white";
this.children = [];
}
Rabbit.prototype.pullFromHat = function() {
return !!Math.floor(Math.random() * 2);
};
Rabbit.prototype.haveChildren = function() {
for (var i = 0; i < 20; i += 1) {
this.children.push(new Rabbit());
}
};
var rabbit = new Rabbit();
alert(rabbit.pullFromHat());
rabbit.haveChildren();
alert("Number of children: " + rabbit.children.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment