Well, it's simply a matter of choice.

Using setTimeout is shorter, simpler, more readable and offers the
same performance. I consider these advantages. Maybe in some other
context setInterval would be a better fit, but in this case I'd go for
simplicity.

cheers,
- ricardo

On Jan 30, 3:56 am, RobG <rg...@iinet.net.au> wrote:
> On Jan 30, 6:57 am, Ricardo Tomasi <ricardob...@gmail.com> wrote:
>
> > I'm not sure there is any difference in performance,
>
> Nor am I, who mentioned performance?  It's about using the tool that's
> intended for the job.
>
> > most animations
> > use setTimeout instead of setInterval for better timing too (though
> > it's irrelevant in this case).
>
> Cool, self-deprecating arguments are easy to respond to.
>
> > And it would require a bit more code.
>
> It would require different code - less is not always more.  Here's a
> setInterval version:
>
>   (function(set) {
>     var i = 0, ref = setInterval(function() {
>       (set[i])? $(set[i++]).fadeIn(500) : clearTimeout(ref);
>     },100);
>   })( $('.sticky:hidden') );
>
> which requires about 40 more characters - are programmers *that*
> lazy?  It can likely be more consise if I knew more about how to
> access items in a jQuery object or the OP wanted to call it other than
> as an anonymous function.
>
> The reason for suggesting setInterval is that its purpose is to run a
> command at a set interval, which seems to be what the OP is after.
> There seems to be a mindset with jQuery that every statement must be
> written in the form $(someSelector).doStuff()... rather than looking
> at individual problems and coding accordingly.  Hence it seems the
> more appropriate setInterval function was overlooked in order to fit
> in with jQuery's coding style.
>
> --
> Rob

Reply via email to