View Full Version : Changing properties added with the Prototype keyword

05-02-2007, 09:39 PM

I have some script like this:

// simplified to remove all the try/catches & stuff
function newXHR() {
request = new XMLHttpRequest();
XMLHttpRequest.prototype.requested = null;
return request;

then later:

function doRequest(url, callback) {
var req = newXHR();
req.requested = url;

// et cetera....

This works fine in Firefox, however the line 'req.requested = url'; causes an error in IE7, (I haven't tested IE6 yet). The error is 'Object doesn't support this property or method'

So, this leads me to believe that either a) XMLHttpRequest.requested is not writable, or, b) XMLHttpRequest.requested was never created in the first place. I think it's the first option because I'm not getting an error in the newXHR() function.

I've been searching for some documentation on this but I can't seem to find anywhere if properties created with the prototype keyword are writeable in IE. Does anyone know what the problem is?



05-02-2007, 10:14 PM
In IE6 the XMLHttpRequest is an ActiveX object, not a native object so you can't set any custom properties on it.

IE7 on the other hand should support it.


Plus I did this quick test on a straight custom property and it worked

<script type="text/javascript">
function doIt(s) {
var adiv = document.getElementById("adiv");
var xhr = new XMLHttpRequest();
xhr.custom_prop = "hiya";
adiv.innerHTML = xhr.custom_prop;
<button onclick="doIt();">Do it</button>
<br />
<div id="adiv"> </div>

But the question was about prototype and from what I read the "native" xhr for IE7 is still not truly native so you can't add to its prototype. Nor can you add to the XMLHttpRequest object itself, so only its instantiated objects.

That's my brain dump on it anyway. ;)