Skip to content

Instantly share code, notes, and snippets.

@brianium
Created December 14, 2014 20:53
Show Gist options
  • Save brianium/04d6ac31abe451a06703 to your computer and use it in GitHub Desktop.
Save brianium/04d6ac31abe451a06703 to your computer and use it in GitHub Desktop.
multiple inheritance in js
function Entity() {
}
Entity.prototype.entityThing = function() {
console.log("entity thing");
};
function NPC(name) {
Entity.call(this);
this.name = name;
}
NPC.prototype = Object.create(Entity.prototype);
NPC.prototype.constructor = NPC;
function Captain(name, hp) {
NPC.call(this, name);
this.hp = hp;
}
Captain.prototype = Object.create(NPC.prototype);
Captain.prototype.constructor = Captain;
Captain.prototype.captainSlashOfFury = function() {
console.log("I am Captain " + this.name + " and I have " + this.hp + " left!");
console.log("Slash slash slash!!!!");
};
var brian = new Captain("Brian", 100);
brian.entityThing();
brian.captainSlashOfFury();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment