[whatwg] 7.3 Timers

On Mon, 28 Feb 2011, Alexandre Morgaut wrote:
> http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html
> I think that "args", the third parameter of setTimeout & setInterval is 
> not enough described
> Should arguments be an Array, or any "Array like" is ok (with indexed 
> properties and a length property) ?

This is defined in Web IDL, which describes the "..." syntax in the IDL 

  long setTimeout(in any handler, in optional any timeout, in any... args);

> When I read: Any arguments are passed straight through to the handler.
> I wonder if it does not mean that I should pass one parameter per argument to pass to the handler
> -> setTimeout( myhandler, 1000, arg1, arg2, arg3);

That is indeed how it is used.

> But well, the signature looks like there is only one parameter so it 
> must be at least an "Array like" object

I've tried to fix the signature in the green boxes.

> Note that, in the process, there is steps to get the handler and the 
> timeout parameters, but I didn't see any for arguments...

It's in the "get the timed task" stuff.

> A common use case with setTimeout is to compute the timeout argument 
> from the current Date to process a function at a specific time
> This can be easily done via a function like this one
> function setToHappen(fn, d){ 
>     var t = d.getTime() - (new Date()).getTime(); 
>     return setTimeout(fn, t); 
> } 
> But couldn't setTimeout() accept natively a Date object in place of the 
> timeout parameter

As you say, it can easily be done (though it needs a bit more work than 
what you describe -- you actually have to fire the task regularly and 
check the time, otherwise your timer will be confused by system suspension 
events). I'd rather not complicate the platform if the feature is already 
technically available.

> Another useful feature would be to support more user friendly duration 
> expressions like
> setInterval(doItAtEachHour, "1 H");
> setTimeout(logout, "20 mn");

Again, this can be done already, it just requires code. So I haven't added 
this natively to the platform. (Adding features is quite expensive.)

On Tue, 1 Mar 2011, Alexandre Morgaut wrote:
> As for a Web "Application", User Agents may provide a setting dialog so 
> it could ask to the user to accept a list of option for the application 
> This way, the user won't miss line on top of the page asking 
> authorizations for each ones
> Example:
> setDomainSettings( message, required, optional);
> where "required" and "optional"  parameters would expect a list of options to activate including:
> - geolocation
> - storage with specific size
> - crons
> - allow popup
> - remember password
> Thoughts ?

Things that prompt the user tend to be dismissed without being read, so 
browser vendors are shying away from this kind of UI.

Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Thursday, 9 June 2011 00:25:33 UTC