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

[XHR2] Readability of Async/Sync in xhr.open

From: Joseph Pecoraro <pecoraro@apple.com>
Date: Sun, 27 Feb 2011 12:51:12 -0800
Message-Id: <9CDD60BA-B0CC-4D2E-BDAE-0EE77F2BEBBF@apple.com>
To: public-webapps@w3.org
Whenever I see the following snippet I never remember if its synchronous or asynchronous and I have to look it up:

    xhr.open('GET', 'example.html', false);

I think it would be much more readable if there were constants for Synchronous / Asynchronous:

    xhr.open('GET', 'example.html', XMLHttpRequest.SYNC);

If authors wanted to "start using it now", they could add the flags themselves:

    XMLHttpRequest.SYNC = false;
    XMLHttpRequest.ASYNC = true;

... or they could do something like the following (since I think undefined may become the default value asynchronous):

    xhr.open('GET', 'example.html', XMLHttpRequest.SYNC || false);

This gets especially hairy when the user + password parameters are needed, and there is a "magic" boolean in the middle:

Suggested values would be SYNC/ASYNC matching the spec's "async" boolean name, or the longer SYNCHRONOUS/ASYNCHRONOUS.

Is this something that would be considered, or is it so easy for authors to make it clear, with comments or variable names, that it is not worth it? Maybe I just need to remember what that boolean means!

- Joseph Pecoraro
Received on Sunday, 27 February 2011 20:51:50 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:16 UTC