This code simply executes xhr.onreadystatechange, xhr.onload and xhr.onloadend. There's a lot of different ways how events can be registered and fired (e.g. if one adds listeners with xhr.addEventListener(...). This means that if you don't register your listeners with one of the three shorthands, they are never fired.
Also, the mentioned code calls the callbacks without event arguments:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readystatechange_event
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/loadend_event
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/load_event
This leads to consumers not being able to access these events in their registered callbacks, which leads to exceptions if they do so. A very simple reproducer:
const x = new XMLHttpRequest();
x.open("GET", location.href);
x.addEventListener("progress", (event) => {
console.log(`progress: ${event.loaded * 100/event.total} %`);
});
x.addEventListener("load", (event) => {
console.log(`loaded ${event.loaded} bytes`);
});
x.send();
In this scenario, none of the events are fired. if you replace the addEventListener calls with the shorthands, you can see that only load is called without the event argument (progress is not called whatsoever):
x.onprogress = (event) => {
console.log(`progress: ${event.loaded * 100/event.total} %`);
};
x.onload = (event) => {
console.log(`loaded ${event.loaded} bytes`);
};
This code simply executes
xhr.onreadystatechange,xhr.onloadandxhr.onloadend. There's a lot of different ways how events can be registered and fired (e.g. if one adds listeners withxhr.addEventListener(...). This means that if you don't register your listeners with one of the three shorthands, they are never fired.Also, the mentioned code calls the callbacks without event arguments:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readystatechange_event
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/loadend_event
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/load_event
This leads to consumers not being able to access these events in their registered callbacks, which leads to exceptions if they do so. A very simple reproducer:
In this scenario, none of the events are fired. if you replace the
addEventListenercalls with the shorthands, you can see that only load is called without theeventargument (progress is not called whatsoever):