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

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:
http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#the-open-method

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