Skip to content

Instantly share code, notes, and snippets.

@tcare
Last active August 29, 2015 14:11
Show Gist options
  • Save tcare/53d3dd5a8a2e57361d10 to your computer and use it in GitHub Desktop.
Save tcare/53d3dd5a8a2e57361d10 to your computer and use it in GitHub Desktop.
ES5 code, without classes
/* 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.");
};
@phistuck
Copy link

Why var Civilian = function Civilian(name) {? Just var Civilian = function (name) { is enough, or more simply, function Civilian(name) {.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment