Created
June 25, 2012 22:43
-
-
Save anthonybrown/2991916 to your computer and use it in GitHub Desktop.
more class emulation in js
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
<script type="text/javascript"> | |
var Animal = function(){}; | |
Animal.prototype.breath = function(){ | |
console.log('inhale'); | |
}; | |
Animal.prototype.heart = function(){ | |
console.log('beating heart'); | |
}; | |
var Dog = function(){}; | |
// Dog inherits from Animal | |
Dog.prototype = new Animal; | |
Dog.prototype.wag = function(){ | |
console.log('wag tail'); | |
}; | |
var Cat = function(){}; | |
//Cat inherits from Animal | |
Cat.prototype = new Animal; | |
Cat.prototype.meow = function() { | |
console.log('meow i\'m a cat'); | |
} | |
var dog = new Dog; | |
dog.wag(); | |
dog.breath(); | |
var cat = new Cat; | |
cat.heart(); | |
dog.breath(); | |
cat.meow(); | |
</scrip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment