[whatwg] Optional non-blocking mode for simple dialogs (alert, confirm, prompt).
Diego Perini
diego.perini at gmail.com
Sun Feb 27 11:10:05 PST 2011
On Sun, Feb 27, 2011 at 11:53 AM, Ben Rimmington <benrimmington at me.com> wrote:
>> 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).
>
Firefox 3.6.13 already returns 4 for "window.prompt.length".
Are the 2 extra parameters already known/used ?
--
Diego
>> 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.
>
>
More information about the whatwg
mailing list