JSFiddle - React, Tailwind, and code Playground

by PeteLopez

JavaScript

(function(){
    var degree = new Degree('foo');
    degree.init();
    var degree = new Degree('bar');
    degree.init();
})();

function Degree(enrollmentType)
{
    this.enrollmentType = enrollmentType;
    
    if (typeof (_degree_prototype_called) == 'undefined') {
        _degree_prototype_called = true;
        Degree.prototype.init = init;
    }
            
    function init(){
        //console.log(enrollmentType);
        
        // Remove the 'this' and you'll get success two times (undesirable)
        // Add 'this' and you'll get one success and one fail (this is the desired behavior)
        switch(this.enrollmentType)
        {
            case 'foo':
                console.log('Success');
                break;
            default:
                console.log('Fail');
                break;
        }
    };
}