Skip to content

Instantly share code, notes, and snippets.

@hhsnopek
Last active August 29, 2015 14:22
Show Gist options
  • Save hhsnopek/3955c5a42f77eecf4375 to your computer and use it in GitHub Desktop.
Save hhsnopek/3955c5a42f77eecf4375 to your computer and use it in GitHub Desktop.
multiple inheritance
// Coffee
class Animal
this.species;
class Human extends Animal
this.species = "mammal";
this.sex;
class Woman extends Human
this.sex = "female";
class Cyborg extends Human extends Animal
this.species = "unknown";
this.sex = male;
// JS
var Animal, Cyborg, Human, Woman,
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Animal = (function() {
function Animal() {}
Animal.species;
return Animal;
})();
Human = (function(superClass) {
extend(Human, superClass);
function Human() {
return Human.__super__.constructor.apply(this, arguments);
}
Human.species = "mammal";
Human.sex;
return Human;
})(Animal);
Woman = (function(superClass) {
extend(Woman, superClass);
function Woman() {
return Woman.__super__.constructor.apply(this, arguments);
}
Woman.sex = "female";
return Woman;
})(Human);
Cyborg = (function(superClass) {
extend(Cyborg, superClass);
function Cyborg() {
return Cyborg.__super__.constructor.apply(this, arguments);
}
Cyborg.species = "unknown";
Cyborg.sex = male;
return Cyborg;
})(extend(Human, Animal));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment