-
-
Save sagivf/5b3ceb16bf9101986b4f to your computer and use it in GitHub Desktop.
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
/* ES5 code, without classes */ | |
var Civilian = function Civilian(name) { | |
this.name = name; | |
}; | |
Civilian.prototype.danger = function () { console.log("Run away!"); }; | |
var SuperHero = function(name, ability) { | |
Civilian.call(this, name); // Call the super class constructor. | |
this.ability = ability; | |
}; | |
SuperHero.prototype = Object.create(Civilian.prototype); | |
SuperHero.prototype.constructor = SuperHero; | |
SuperHero.prototype.danger = function () { // Override the super class method. | |
console.log("Never fear, " + this.name + " is here!"); | |
console.log(this.name + " uses " + this.ability + ". It's super effective."); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment