[OpenLayers-Dev] javascript keys vs counter

Christopher Schmidt crschmidt at metacarta.com
Fri Oct 12 12:17:54 EDT 2007


On Fri, Oct 12, 2007 at 12:03:10PM -0400, Jacob Westfall wrote:
> On Thu, 11 Oct 2007 11:24:48 -0400
> Christopher Schmidt <crschmidt at metacarta.com> wrote:
> > for (item in feats) {  }
> > 
> > will return 0, 1, 2, etc.
> > 
> > It's the keys, not the objects, which are returned.
> > 
> > However, in general, you should just use the for (i = 0; i <
> > feats.length; i++) types -- there are resources on the web that you can
> > read about why and how, I'm sure, I'm just not up to researching them at
> > the moment :)
> 
> Hi,
> 	I haven't been able to find the resources you mention about this issue.  Should I be searching for keys versus counters?  Thanks,

I think that I was thinking along the lines of:

http://ajaxian.com/archives/javascript-associative-arrays-considered-harmful

"The other problem with using Arrays as associative arrays means you can
no longer extend Array.prototype, which is what Prototype 1.5 does to
great effect." 

"So use Object for associative arrays, and use Array for numeric arrays.
Of course, there will always be exceptions, "no best practices", yadda
yadda - but just be aware of the danger and possible confusion if you do
violate this."

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list