JSFiddle - React, Tailwind, and code Playground

by chrisramakers

JavaScript

// Base class
function Mammal(color, name, gender){
    this.color  = color;
    this.name   = name;
    this.gender = gender;
    this.offspring = [];
}
Mammal.prototype.toString = function(){
    return '['+this.name+' Mammal]';
}
Mammal.prototype.giveBirth = function(color, name, gender){
    var kitten = new Mammal(color, name, gender);
    this.offspring.push(kitten);
    return kitten;
}

// Extend Mammal into Cat
function Cat(color, name, gender){
    Mammal.apply(this, arguments);
}
Cat.prototype = new Mammal();
Cat.prototype.toString = function(){
    return '['+this.name+' Cat]';
}


// Create a Cat
var kittie = new Cat('white', 'Kittie', 'f');

// Let Cat give birth
var littleKittie = kittie.giveBirth('black', 'Little Kittie', 'm');

// Output
document.write(kittie, '<hr>');
//document.write(littleKittie);