Skip to content

Instantly share code, notes, and snippets.

@anthonybrown
Created June 25, 2012 22:43
Show Gist options
  • Save anthonybrown/2991916 to your computer and use it in GitHub Desktop.
Save anthonybrown/2991916 to your computer and use it in GitHub Desktop.
more class emulation in js
<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