Baseball Pitcher Eval Object Constructor Pattern

Using an Object Constructor Pattern, we can enter player evaluations for pitchers.

by MIRRO_Inc

JavaScript

function pitcherEval(theName, theFastball, theOffSpeedTypes, theVelocity, theMechanics) {

    this.name = theName;
    this.fastball = theFastball;
    this.offSpeedTypes = theOffSpeedTypes;
    this.velocity = theVelocity;
    this.mechanics = theMechanics;

    this.pitcherName = function () {
        console.log("This evaluation is for player: " + this.name);
    };

    this.pitcherFastball = function () {
        this.fastball.forEach(function (eachType) {
            console.log("This pitcher throws a:" + eachType + "fastball");
        });
    };

    this.pitcherOffSpeedTypes = function () {
        this.offSpeedTypes.forEach(function (eachTypeOfOffSpeed) {
            console.log("They throw a:" + eachTypeOfOffSpeed);
        });
    };

    this.pitcherVelocity = function () {
        this.velocity.forEach(function (velocityRange) {
            console.log("Their velocity for:" + velocityRange);
        });
    };

    this.pitcherMechanics = function () {
       this.mechanics.forEach(function (playerMechanics) {
            console.log("This pitcher's mechanics are:" + playerMechanics);
        });
    };
}

var pitcherEval = new pitcherEval("Greg Maddux", ["2-Seam", "Cut", "Occasional 4-Seam after Change-Up"], ["Above-Average Change-Up", "Soft 2-8 CB"], ["FB 85-88mph", "CH 76-78mph", "2-8 73-75mph"], ["Clean arm action", "Simple delivery", "Repeatable with little variation", "Can get to slow and deliberate"]);

pitcherEval.pitcherName();
pitcherEval.pitcherFastball();
pitcherEval.pitcherOffSpeedTypes();
pitcherEval.pitcherVelocity();
pitcherEval.pitcherMechanics();