JSFiddle - React, Tailwind, and code Playground

by Chase Wilson

JavaScript

var XHR = (function(){
    var instances = [];
    instances.push({
        getInstance: function(){
            return new XMLHttpRequest();
        }
    });
    
    instances.push({
        getInstance: function(){
            return new ActiveXObject('Msxml2.XMLHTTP');    
        }
    });
    
    instances.push({
        getInstance: function(){
            return new ActiveXObject('Microsoft.XMLHTTP');   
        }
    });
    
    var i = -1;
    var tryInstance = function(){
        if(i < instances.length){
            i++;
            try{
                console.log(i);
                var obj = instances[i].getInstance();
                return instances[i];
            }catch(e){
                tryInstance();
            }
        } else {
            return false;
        }
    };
   
    return tryInstance();
   
})();

var xhrInstance = XHR.getInstance();