JSFiddle - React, Tailwind, and code Playground

JavaScript

function Ball() {
    this.play = function() {
        alert("Ball throw");
    };
}

function Basketball() {
    this.play = function() {
        alert("basketball throw");
    };
}

function Soccerball() {
    this.play = function() {
        alert("soccer ball kick/throw");
    };
}

function Baseball() {
    this.play = function() {
        alert("soccer ball kick/throw");
    };
}

Basketball.prototype = new Ball();
Soccerball.prototype = new Ball();
Baseball.prototype = new Ball();

var bunchOfBalls = [new Baseball(), new Soccerball(), new Basketball()];
for (var i = 0; i < bunchOfBalls.length; i++) {
    bunchOfBalls[i].play();
}

//overloading dependent upon type
function BasketbalOrBaseballOnlyPlay(aBall) {
    if (aBall instanceof Basketball) {
        //special basketball function
    }
    if (aBall instanceof Baseball) {
        //special baseball function
    }
}

aBall = new Baseball();
alert(aBall instanceof Ball);