Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
Created March 5, 2015 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapthedingbat/9aa9054115cffe6aa58a to your computer and use it in GitHub Desktop.
Save zapthedingbat/9aa9054115cffe6aa58a to your computer and use it in GitHub Desktop.
Classic Inheritance JS
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