Created
March 27, 2016 23:24
-
-
Save wavebeem/fdc3fab86b075f95266c 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 fly(creature) { | |
return ( | |
"The " + creature.species + | |
" flies using its " + creature.methodOfFlight | |
); | |
} | |
function hunt(creature, otherCreature) { | |
return ( | |
"The " + creature.species + | |
" hunts the " + otherCreature.species + | |
" using its " + creature.methodOfHunting | |
); | |
} | |
function CreateCreature(species) { | |
return {species}; | |
} | |
function CreatePredator(species, methodOfHunting) { | |
const creature = {species, methodOfHunting}; | |
creature.hunt = hunt.bind(null, creature); | |
return creature; | |
} | |
function CreateFlyingPredator(species, methodOfFlight, methodOfHunting) { | |
const creature = {species, methodOfFlight, methodOfHunting}; | |
creature.fly = fly.bind(null, creature); | |
creature.hunt = hunt.bind(null, creature); | |
return creature; | |
} | |
const rabbit = CreatePredator("rabbit"); | |
const wolf = CreatePredator("wolf", "teeth"); | |
const eagle = CreateFlyingPredator("eagle", "wings", "talons"); | |
console.log(rabbit); | |
console.log(eagle); | |
console.log(wolf); | |
console.log(wolf.hunt(rabbit)); | |
console.log(eagle.hunt(wolf)); | |
console.log(eagle.fly()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment