Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rhocairn/a79f6c11d840a7f9c120 to your computer and use it in GitHub Desktop.
Save rhocairn/a79f6c11d840a7f9c120 to your computer and use it in GitHub Desktop.
function Animal(genus, species) {
var animal = Object.create(Animal.prototype);
animal.genus = genus;
animal.species = species;
return animal;
}
function Dog(species) {
var dog = Object.create(Dog.prototype);
dog.genus = 'Canis';
dog.species = species;
return dog;
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
function Animal(genus, species) {
var animal = Object.create(Animal.prototype);
animal.init(genus, species);
return animal;
}
Animal.prototype.init = function(genus, species) {
this.genus = genus;
this.species = species;
}
function Dog(species) {
var dog = Object.create(Dog.prototype);
dog.init('Canis', species);
return dog;
}
Dog.prototype = Object.create(Animal.prototype);
function Animal(genus, species) {
var animal = Object.create(Animal.prototype);
animal.genus = genus;
animal.species = species;
return animal;
}
function Dog(species) {
var dog = Animal.prototype.constructor.call(this, 'Canis', species);
dog.__proto__ = Object.create(Dog.prototype);
return dog;
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment