Can anyone help me change this code to a class. I’m messing up with the this context between the class and the xmlhttpprotoype.
(function () {
const XHR = XMLHttpRequest.prototype;
const open = XHR.open;
const send = XHR.send;
XHR.open = function (
method: string,
url: string | URL,
async: boolean = true,
username?: string | null,
password?: string | null
) {
const strURL = url.toString();
XHR.send = function (...args) {
if (strURL && strURL.startsWith("/api")) {
this.addEventListener("load", listenerFn);
}
send.apply(this, args);
};
open.call(this, method, url, async, username, password);
};
})();