Search code examples
javascriptxmlhttprequestspecificationswindow-objectwebidl

How does XMLHttpRequest relate to the JS Window object


While reading up on XMLHttpRequest found out that it is a member of the high level JS global window object. For instance:

if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+ ...
    httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 6 and older
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}

But I can't confirm this information anywhere else? I looked up here https://developer.mozilla.org/en-US/docs/Web/API/Window to see if I could locate the XMLHttpRequest object but there wasn't any mentioning of it. Am I missing something? Just want to make sure I am understanding the correct origin of XMLHttpRequest and how it relates to the global window object.


Solution

  • See the WebIDL definition for the XMLHttpRequest interface:

    [Constructor, Exposed=(Window,DedicatedWorker,SharedWorker)]
    interface XMLHttpRequest : XMLHttpRequestEventTarget {
    …
    }
    

    So that requires XMLHttpRequest to be exposed from Window and also from DedicatedWorker and SharedWorker (in UAs that actually implement those).