Created
August 10, 2013 01:24
-
-
Save nemrow/6198595 to your computer and use it in GitHub Desktop.
This file contains 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 Mammal(options){ | |
this.name = options.name; | |
this.sex = options.sex; | |
this.alive = true; | |
} | |
function Person(options){ | |
Mammal.call(this, options); | |
this.children = []; | |
this.wife; | |
this.husband; | |
this.mother; | |
this.father; | |
this.pets = []; | |
} | |
function Dog(options){ | |
this.name = options.name | |
this.sex = options.sex | |
this.owner; | |
this.alive = true; | |
}; | |
Mammal.prototype.kill = function(){ | |
this.alive = false; | |
}; | |
Dog.prototype = Object.create(Mammal.prototype); | |
Person.prototype = Object.create(Mammal.prototype); | |
Person.prototype.procreateWith = function(partner, options){ | |
if (partner === this){ | |
throw "you cannot have a baby with yourself!"; | |
}else if (partner.sex == this.sex && this.sex == 'male'){ | |
throw "two men cannot have a baby!"; | |
}else{ | |
var child = new Person(options) | |
this.children.push(child); | |
this.spouse().children.push(child); | |
if (this.sex == 'male'){ | |
child.mother = this.spouse(); | |
child.father = this; | |
}else{ | |
child.father = this.spouse(); | |
child.mother = this; | |
}; | |
return child; | |
} | |
}; | |
Person.prototype.spouse = function(){ | |
if(this.sex == 'male'){ | |
return this.wife; | |
}else{ | |
return this.husband; | |
} | |
}; | |
Person.prototype.scream = function() { | |
return "MY NAME IS " + this.name.toUpperCase() + "!"; | |
}; | |
Person.prototype.wed = function(spouse){ | |
if (this.sex == 'male'){ | |
this.wife = spouse | |
spouse.husband = this | |
}else{ | |
this.husband = spouse | |
spouse.wife = this | |
}; | |
}; | |
Person.prototype.buyPet = function(type, options){ | |
pet = new type(options); | |
this.pets.push(pet); | |
pet.owner = this; | |
return pet; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment