Created
March 5, 2015 18:08
-
-
Save zapthedingbat/9aa9054115cffe6aa58a to your computer and use it in GitHub Desktop.
Classic Inheritance 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
Function.prototype.extends=function(base){ | |
var t = function () {} | |
t.prototype = base.prototype; | |
this.prototype = new t(); | |
this.prototype.constructor = this; | |
}; | |
var Animal = function(){ | |
this.isAlive = true; | |
} | |
Animal.prototype.die = function(){ | |
this.isAlive = false; | |
} | |
var Dog = function(){ | |
// Call the base constructor | |
Animal.apply(this, arguments); | |
} | |
Dog.extends(Animal); | |
/***** | |
* var dog = new Dog(); | |
* alert(dog.isAlive); | |
* dog.die(); | |
* alert(dog.isAlive); | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment