Last active
August 29, 2015 14:22
-
-
Save AmaxJ/1f2554d81092d0b5c25b to your computer and use it in GitHub Desktop.
inherits
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(){ | |
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