Skip to content

Instantly share code, notes, and snippets.

@paulbaumgart
Created January 26, 2011 01:01
Show Gist options
  • Save paulbaumgart/796032 to your computer and use it in GitHub Desktop.
Save paulbaumgart/796032 to your computer and use it in GitHub Desktop.
_XMLHttpRequest = XMLHttpRequest;
XMLHttpRequest = function () {
Object.defineProperty(this,
"__onreadystatechange",
{value: null,
writable: true,
enumerable: false});
Object.defineProperty(this,
"onreadystatechange",
{get: (function() { return this.__onreadystatechange; }),
set: (function(val) {
if (this.__onreadystatechange && typeof this.__onreadystatechange.call === "function")
this.removeEventListener("readystatechange", this.__onreadystatechange);
this.__onreadystatechange = val;
if (this.__onreadystatechange && typeof this.__onreadystatechange.call === "function")
this.addEventListener("readystatechange", this.__onreadystatechange);
}),
enumerable: true});
}
XMLHttpRequest.prototype = new _XMLHttpRequest();
@tlrobinson
Copy link

Do you need to do something like _XMLHttpRequest.call(this) in the "subclass" constructor to initialize anything?

@paulbaumgart
Copy link
Author

Does it not work as expected? There is no call property on the XHR object:
_XMLHttpRequest = XMLHttpRequest
function XMLHttpRequest() { [native code] }
_XMLHttpRequest.call
undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment