[whatwg] Optional non-blocking mode for simple dialogs (alert, confirm, prompt).

Glenn Maynard glenn at zewt.org
Sun Feb 27 02:19:30 PST 2011


On Sun, Feb 27, 2011 at 3:57 AM, Ben Rimmington <benrimmington at me.com>wrote:

> >> For user agents that don't support the updated API:
> >>
> >>> function promptWrapper(message, default, callback) {
> >>>     var result = window.prompt(message, default, callback);
> >>>     if (callback && (typeof callback === "function")) {
> >>>         if (result !== callback) {
> >>>             callback(result);
> >>>         }
> >>>         return callback;
> >>>     }
> >>>     return result;
> >>> }
> >
> > Of course, that would be a synchronous callback rather than an async
> one...
>
> On 27 Feb 2011, at 00:08, Adam Barth wrote:
> That's true, a compatibility layer such as promptWrapper() would need to
> use window.setTimeout() for an async callback. The example code was mainly
> intended to show how "feature detection" of the non-blocking mode could be
> implemented.
>

Feature detection needs to be possible without actually calling the
function--without actually opening a prompt.  For example, if you're to run
the above prompt from a timeout, you need to know that *before* you call
prompt(), since you don't want a timeout if the async API is supported.

The pattern in new APIs like IDB and FileAPI is to have separate sync and
async interfaces, not overloaded behavior, eg:

promptAsync(message, default, callback);

Better off just leaving this crusty old API in the legacy bin, though.

-- 
Glenn Maynard


More information about the whatwg mailing list