Created
October 4, 2013 21:44
-
-
Save WizardNinja/6833293 to your computer and use it in GitHub Desktop.
animals.js run this on repl.it
This file contains hidden or 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
| Animal = function(name,sound) { | |
| if(name) { | |
| this.name = name; | |
| } | |
| if(sound) { | |
| this.sound = sound; | |
| } | |
| } | |
| Animal.prototype = { | |
| introduce: function() { | |
| console.log("The " + this.name + " goes " + this.sound); | |
| }, | |
| isAnimal: function() { | |
| return !!this.animal; | |
| }, | |
| isMammal: function() { | |
| return !!this.mammal; | |
| }, | |
| isReptile: function() { | |
| return !!this.reptile; | |
| }, | |
| isBird: function() { | |
| return !!this.bird; | |
| } | |
| } | |
| Animal.prototype.animal = true; | |
| Mammal = function(name,sound) { | |
| Animal.apply(this, [name,sound]); | |
| } | |
| Mammal.prototype = new Animal; | |
| Mammal.prototype.mammal = true; | |
| Reptile = function(name, sound) { | |
| Animal.apply(this, [name,sound]); | |
| } | |
| Reptile.prototype = new Animal; | |
| Reptile.prototype.reptile = true; | |
| Bird = function(name, sound) { | |
| Animal.apply(this, [name,sound]); | |
| } | |
| Bird.prototype = new Animal; | |
| Bird.prototype.bird = true; | |
| Fish = function(name, sound) { | |
| Animal.apply(this, [name,sound]); | |
| } | |
| Fish.prototype = new Animal; | |
| Fish.prototype.fish = true; | |
| fox = new Mammal("fox", "ancient mystery"); | |
| console.log(fox.isBird()); | |
| console.log(fox.isMammal()); | |
| elephant = new Mammal("elephant", "ewaaaaaa!!"); | |
| cow = new Mammal("cow", "moo"); | |
| goldfish = new Fish("goldfish", "blub"); | |
| parakeet = new Bird("parakeet", "tweet"); | |
| elephant.introduce(); | |
| cow.introduce(); | |
| goldfish.introduce(); | |
| parakeet.introduce(); | |
| fox.introduce(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment