JSFiddle - React, Tailwind, and code Playground

by lawrence pond

JavaScript

// JavaScript Inheritance Fake Abstract Class.

var Animal = {
    
    foodType :"None",
    feed: function() {
        console.log("Fed the animal:" +this.foodType);
    }
};


function Cow(color)
{
    this.color = color;
    this.foodType ="Hay";
}
//var a = new Animal(); // Fails (not a constructor)

//Animal is a single instacnce itself;

// Inheritance Magics
alert(true);
Cow.prototype = Animal;

var c = new Cow("White/Black");
c.feed();
//var test = c  instanceof Animal; // error  this is a problem 
var test2 = c instanceof Cow;  // true
alert(test);