views:

1737

answers:

1

This is partially a request for a workaround, and partially an attempt to get the word out that Internet Explorer's prototype implementation is still faulty.

The following code does not work on Internet Explorer.

XMLHttpRequest.prototype.old = XMLHttpRequest.prototype.open;
var x = new XMLHttpRequest();
x.old("POST", "test", false);

For IE 8 beta, and all previous versions, the XMLHttpRequest.prototype property never existed in the first place. In IE8, it does exist, but you'll get a "Invalid procedure call or argument" error. Internet Explorer doesn't like decoration.

Does anyone know of a workaround for this?

Update:

It has been pointed that I could override the entirety of XMLHttpRequest with a new function and constructor, and then create a wrapper script ala XMLHttpRequest.js. The prototype method is much shorter, so I would still prefer to use it for non-IE browsers.

+2  A: 

Would this page offer a solution?

KooiInc
Arguably using prototype to surgically override methods is much more elegant (30 lines versus 300 lines). That said, if I want to support IE, I'll probably have to do what that page suggests.
Edward Z. Yang
I'd say that's the solution. Thanks for answering!
Edward Z. Yang