---
title: "Simple Closure for Cross Browser XHR Instance"
description: "Yes that is right, there are many libraries to handle XHR, but raw JS is always fun! There are many ways of doing this, but."
url: "https://h3manth.com/scribe/simple-closure-cross-browser-xhr-instance/"
canonical_url: "https://h3manth.com/scribe/simple-closure-cross-browser-xhr-instance/"
markdown_url: "https://h3manth.com/scribe/blog/simple-closure-cross-browser-xhr-instance.md"
publishDate: "2011-11-14T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["nodejs","web"]
word_count: 138
reading_time_minutes: 1
x_markdown_tokens: 325
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Simple Closure for Cross Browser XHR Instance

> Yes that is right, there are many libraries to handle XHR, but raw JS is always fun! There are many ways of doing this, but.

**Yes that is right, there are many libraries to handle XHR, but raw JS is always fun!**

_There are many ways of doing this, but here is a unique way of getting an XHR instance._

**A simple closure, that tries to create a simple XHR instance :**

var req = (function () {  
try {  
return new(this.XMLHttpRequest || ActiveXObject)('MSXML2.XMLHTTP.3.0')  
} catch (e) {}  
})();

**The 'req' var dump on V8 would be like :**

{  
readyState ":0,"  
onloadstart ":null,"  
withCredentials ":false,"  
onerror ":null,"  
onabort ":null,"  
status ":0,"  
responseXML ":null,"  
onload ":null,"  
onprogress ":null,"  
upload ":{"  
onloadstart ":null,"  
onabort ":null,"  
onerror ":null,"  
onload ":null,"  
onprogress ":null},"  
statusText ":"","  
responseText ":"","  
UNSENT ":0,"  
OPENED ":1,"  
HEADERS_RECEIVED ":2,"  
LOADING ":3,"  
DONE ":4  
}

**So, thus a silly script was made just for the LOLz of it! Do suggest your way ;)**
