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

> 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.

You'd only need to use window.setTimeout() if window.prompt() ignored your callback argument and didn't return it:

> function promptWrapper(message, default, callback) {
>     var result = window.prompt(message, default, callback);
>     if (callback && (typeof callback === "function")) {
>         if (result !== callback) {
>             /*** INSTEAD OF: callback(result); ***/
>             window.setTimeout(callback, 1, result);
>         }
>         return callback;
>     }
>     return result;
> }

However, as you pointed out, this "feature detection" only occurs after window.prompt() is invoked. A better way might be to test the window.prompt.length property (if 3 or more then non-blocking mode 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.

Agreed.

Received on Sunday, 27 February 2011 02:53:16 UTC