Skip to content

Instantly share code, notes, and snippets.

@AmaxJ
Last active August 29, 2015 14:22
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 AmaxJ/1f2554d81092d0b5c25b to your computer and use it in GitHub Desktop.
Save AmaxJ/1f2554d81092d0b5c25b to your computer and use it in GitHub Desktop.
inherits
(function(){
var inherits = function(subClass, superClass){
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
}
var inherits2 = function (ChildClass, ParentClass) {
function Surrogate () {}
Surrogate.prototype = ParentClass.prototype;
ChildClass.prototype = new Surrogate();
}
var Human = window.Human = function(name, sex){
this.name = name;
this.sex = sex;
}
Human.prototype.greet = function(name){
console.log("Hello " + this.name);
}
var Hero = window.Hero = function(power, name, sex){
Human.call(this, name, sex);
this.power = power;
}
inherits2(Hero, Human);
//inherits(Hero, Human);
var superman = new Hero("everything", "Clark", "male");
var aquaman = new Hero("Underwater Breathing", "IDK", "male");
var div = document.getElementById("dynamic");
var h2 = document.createElement("h2");
h2.textContent = superman.power + " " + aquaman.power;
div.appendChild(h2);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment