W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2012

[Bug 16223] New: Change .readyState to use string values rather than numeric constants

From: <bugzilla@jessica.w3.org>
Date: Sun, 04 Mar 2012 00:12:40 +0000
To: public-webapps@w3.org
Message-ID: <bug-16223-2927@http.www.w3.org/Bugs/Public/>
https://www.w3.org/Bugs/Public/show_bug.cgi?id=16223

           Summary: Change .readyState to use string values rather than
                    numeric constants
           Product: WebAppsWG
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: WebSocket API (editor: Ian Hickson)
        AssignedTo: ian@hixie.ch
        ReportedBy: jonas@sicking.cc
         QAContact: public-webapps-bugzilla@w3.org
                CC: mike@w3.org, public-webapps@w3.org


Numeric constants sucks when used in javascript. Code like

if (ws.readyState == WebSocket.CONNECTING) { ... }

is both harder to read and harder to type compared to

if (ws.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 'WebSocket.CONNECTING'.

It's even likely that comparing to a string is faster than comparing to
WebSocket.CONNECTING since the latter involves a property lookup.

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
Received on Sunday, 4 March 2012 00:12:41 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:50 GMT