创建XMLHttpRequests的方法

                <div class="grid--cell fl1 lh-lg">
                    <div class="grid--cell fl1 lh-lg">
                        It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and   cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened,   <a href="/help/reopen-questions">visit the help center</a>.

                    </div>
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2012-05-04 13:29:36Z" class="relativetime">7 years ago</span>.</div>
        </div>
    </aside>

I just started learning ajax recently and Im researching ways of creating HttpRequests
These are the ways I have come up with so far:

function one() {
if(window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
    alert('Other');
} else if (window.ActiveXObject) {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
    alert('windows');
}
return xhr;
}


function two() {
    if(window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
        alert('Other');
    } else if (!window.XMLHttpRequest) {
        xhr = new ActiveXObject('Microsoft.XMLHTTP');
        alert('windows');
    }
    return xhr;
}

function three() {
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
        alert('Other');
    } else {
        xhr = new ActiveXObject();
        alert('windows');
    }
    return xhr;
}

function four() {
    try {
        xhr = new XMLHttpRequest();
        alert('Other');
    } catch (e) {
        xhr = new ActiveXObject();
        alert('windows');
    }
    return xhr;
}

I would like to know more ways of creating the request. If anyone has any other methods of doing this please share them. Part of what I like about Javascript is there are many ways of accomplishing the same tasks and I like to explore all possible options.

</div>

I generally defer to jQuery when looking for good ways to do things,

// Functions to create xhrs
function createStandardXHR() {
    try {
        return new window.XMLHttpRequest();
    } catch( e ) {}
}

function createActiveXHR() {
    try {
        return new window.ActiveXObject( "Microsoft.XMLHTTP" );
    } catch( e ) {}
}

// Create the request object
// (This is still attached to ajaxSettings for backward compatibility)
jQuery.ajaxSettings.xhr = window.ActiveXObject ?
    /* Microsoft failed to properly
     * implement the XMLHttpRequest in IE7 (can't request local files),
     * so we use the ActiveXObject when it is available
     * Additionally XMLHttpRequest can be disabled in IE7/IE8 so
     * we need a fallback.
     */
    function() {
        return !this.isLocal && createStandardXHR() || createActiveXHR();
    } :
    // For all other browsers, use the standard XMLHttpRequest object
    createStandardXHR;

Source

function four() {
  try {
    return new XMLHttpRequest(); 
  } catch (e) // Catch ReferenceError
    return new window.ActiveXObject("Microsoft.XMLHTTP");
  }
}