Bug 16224 - Change .readyState to use string values rather than numeric constants
Summary: Change .readyState to use string values rather than numeric constants
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Server-Sent Events (editor: Ian Hickson) (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2012-03-04 00:14 UTC by Jonas Sicking
Modified: 2012-03-13 03:57 UTC (History)
3 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Jonas Sicking 2012-03-04 00:14:17 UTC
Numeric constants sucks when used in javascript. Code like

if (es.readyState == EventSource.CONNECTING) { ... }

is both harder to read and harder to type compared to

if (es.readyState == "connecting") { ... }

All the uppercase letters are a pain to type and and stick out like a sore thumb.

Additionally there's a very real risk that people will write code like

if (ws.readyState == 0) { ... }

since '0' is so much easier to write than 'EventSource.CONNECTING'.

It's even likely that comparing to a string is faster than comparing to EventSource.CONNECTING since the latter involves a property lookup.
Comment 1 Ian 'Hixie' Hickson 2012-03-13 03:57:52 UTC
While I agree with the design principle, I think it's not a big enough win to be worth the churn here. People complain all the time that we keep changing things — we should only do it when we have a truly compelling reason (e.g. a security problem).

In practice, little non-debug code will likely end up using eventsource.readyState anyway. It's easier to use the events. It was mostly added for consistency with XMLHttpRequest, which also uses numbers — and people don't generally find it onerous to remember which readyState is which for that API.