whatwg/xhr

How come `onreadystatechange` is the only event handler defined by default ?

shacharz opened this issue · 8 comments

https://xhr.spec.whatwg.org/#idl-index

onreadystatechange is defined in the constructor but not other event handlers.
Which causes it to have a propertyDescriptor while other event handlers don't.
How come ?

They are inherited from XMLHttpRequestEventTarget.

They are inherited from XMLHttpRequestEventTarget.

Yea, why was XMLHttpRequestEventTarget specified like that ?

Because there's also XMLHttpRequestUpload and we typically inherit from EventTarget where possible.

Not sure I understand, I'm asking how come onreadystatechange is defined but onload,onloadend,onprogress, etc' aren't

They are defined, just higher up in the prototype chain.

Got it, this helped me.
So what I don't understand in terms of implementation is how come by default there's PropertyDescriptor on window.XMLHttpRequest.prototype for onreadystatechange and not all the other events (consistent between Safari, Chrome, Firefox)

Because they're higher up on the prototype chain, I can recommend https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain or asking on Stackoverflow.

(https://heycam.github.io/webidl/ defines the translation from IDL to JavaScript objects, if you want to know the details, but it might be hard to follow.)

Will do, Thanks!