[XMLHttpRequest] readyState values should be available as named constants of the XMLHttpRequest constructor

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[XMLHttpRequest] readyState values should be available as named constants of the XMLHttpRequest constructor

Geoffrey Garen

Hi folks.

I would like to suggest making the canonical readyState values  
available as named constants of the XMLHttpRequest constructor, like so

      0 UninitializedReadyState
      1 OpenReadyState
      2 SentReadyState
      3 ReceivingReadyState
      4 LoadedReadyState

This code

      if (request.readyState == XMLHttpRequest.OpenReadyState) { ... }

is more readable to me that this code

      if (request.readyState == 1) { ... }

which uses a magic number. The DOM 3 APIs tend to use named constants  
like this.

Thanks,
Geoff Garen



Reply | Threaded
Open this post in threaded view
|

Re: [XMLHttpRequest] readyState values should be available as named constants of the XMLHttpRequest constructor

Anne van Kesteren-2

On Tue, 06 Mar 2007 23:23:20 +0100, Geoffrey Garen <[hidden email]>  
wrote:

> I would like to suggest making the canonical readyState values available  
> as named constants of the XMLHttpRequest constructor, like so
>
>       0 UninitializedReadyState
>       1 OpenReadyState
>       2 SentReadyState
>       3 ReceivingReadyState
>       4 LoadedReadyState
>
> This code
>
>       if (request.readyState == XMLHttpRequest.OpenReadyState) { ... }
>
> is more readable to me that this code
>
>       if (request.readyState == 1) { ... }
>
> which uses a magic number. The DOM 3 APIs tend to use named constants  
> like this.

Some initial drafts used to have this and it was removed because of  
comments, iirc, from Maciej among other people. If enough authors and  
implementors support this idea though I suppose we can reconsider that.  
Anyone?


--
Anne van Kesteren
<http://annevankesteren.nl/>
<http://www.opera.com/>

Reply | Threaded
Open this post in threaded view
|

Re: [XMLHttpRequest] readyState values should be available as named constants of the XMLHttpRequest constructor

Maciej Stachowiak


On Mar 9, 2007, at 8:43 AM, Anne van Kesteren wrote:

>
> Some initial drafts used to have this and it was removed because of  
> comments, iirc, from Maciej among other people. If enough authors  
> and implementors support this idea though I suppose we can  
> reconsider that. Anyone?

I think at the time I made my comments we were trying to be strictly  
compatible, i.e. not add anything to the spec that wouldn't work in  
current UAs. Since then, we've given up that principle, for instance  
by making XHR and EventTarget, so I don't think my past reasoning  
stands.

Regards,
Maciej


Reply | Threaded
Open this post in threaded view
|

Re: [XMLHttpRequest] readyState values should be available as named constants of the XMLHttpRequest constructor

Anne van Kesteren-2

On Fri, 09 Mar 2007 19:56:13 +0100, Maciej Stachowiak <[hidden email]>  
wrote:
>> Some initial drafts used to have this and it was removed because of  
>> comments, iirc, from Maciej among other people. If enough authors and  
>> implementors support this idea though I suppose we can reconsider that.  
>> Anyone?
>
> I think at the time I made my comments we were trying to be strictly  
> compatible, i.e. not add anything to the spec that wouldn't work in  
> current UAs. Since then, we've given up that principle, for instance by  
> making XHR and EventTarget, so I don't think my past reasoning stands.

Fair enough, I added constants for consistency with other DOM APIs (the  
names slightly differ from the original request though, please review):

   http://dev.w3.org/cvsweb/~checkout~/2006/webapi/XMLHttpRequest/Overview.html?content-type=text/html;%20charset=utf-8

Thanks for your comments!


--
Anne van Kesteren
<http://annevankesteren.nl/>
<http://www.opera.com/>

Reply | Threaded
Open this post in threaded view
|

Re: [XMLHttpRequest] readyState values should be available as named constants of the XMLHttpRequest constructor

Geoffrey Garen

> Fair enough, I added constants for consistency with other DOM APIs  
> (the names slightly differ from the original request though, please  
> review):

Looks good to me.

Geoff