Skip to content

Instantly share code, notes, and snippets.

@nemrow
Created August 10, 2013 00:50
Show Gist options
  • Save nemrow/6198503 to your computer and use it in GitHub Desktop.
Save nemrow/6198503 to your computer and use it in GitHub Desktop.
function livingThing(options){
this.name = options.name;
this.sex = options.sex;
this.alive = true;
}
function Person(options){
livingThing.call(this, options);
this.children = [];
this.wife;
this.husband;
this.mother;
this.father;
this.pets = [];
}
Person.prototype = Object.create(livingThing.prototype);
Person.prototype.kill = function(){
this.alive = false;
};
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.procreate = function(options) {
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.wed = function(spouse){
if (this.sex == 'male'){
this.wife = spouse
spouse.husband = this
}else{
this.husband = spouse
spouse.wife = this
};
};
function Dog(options){
this.name = options.name
this.sex = options.sex
this.owner;
this.alive = true;
};
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