On Fri, Feb 18, 2011 at 4:04 PM, Nick Morgan <[email protected]> wrote:
>
> Whenever I show anyone code like this though, they say "you should cache
> the length property - you're looking it up on each iteration". So, what do
> you guys think? To me, the second option smacks of premature optimisation.
>
The *only* real perf-wise *reason to cache* the length of the array you're
iterating *is* for a *live-query* such as dom queries. For regular arrays,
it really just is not worth the extra variable.
Obviously the same goes for something like jquery's $foo.size(); or worse,
$('#foo').size(). I'm only talking about the length of the array being
iterated. But that should go without sayin...
I hate it when people say "you should cache arr.length because it's faster".
While technically maybe true, it's just bullshit. But maybe that's just me
;)
- peter
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]