On Sat, Dec 12, 2009 at 3:38 PM, Garrett Smith <dhtmlkitc...@gmail.com>wrote:

> On Sat, Dec 12, 2009 at 2:59 PM, Mark S. Miller <erig...@google.com>
> wrote:
> > Are we really this stuck? Can anyone think of a reliable, portable, and
> fast
> > ES3R test that tests whether a property is enumerable, whether it is
> > inherited or not?
> >
>
> Not stuck. Why do you care if |length| is enumerable?
>
> If a standard |for| loop is used, it doesn't matter.  Why anyone would
> want to use |for in| for something that is arrayLike?
>


|for in| is not my concern. I wish a predicate that has little chance of
false positives against legacy ES3 user constructed objects. If

    var obelisk = {
      width: 9,
      length: 16,
      height: 25
    };

appears in some existing code, I don't want a predicate that decides the
obelisk is array-like, as it was clearly not the intent. The reason I care
about enumerability is that legacy ES3R code has no way to create an
ordinary native object with a non-enumerable length property, thereby
preventing false positives in against legacy ES3R objects.

OTOH, your examples of false DOM negatives below are sufficiently
discouraging that perhaps this whole exercise is fruitless. Perhaps there is
no coherent notion of array-like to be rescued from current practice.




> Can an arrayLike object have other properties? If you're talking about
> a DOM collection, you can be that it will have other properties and
> probably a mix of enumerable and non-enumerable proprietary
> properties.
>
> A DOM collection (NodeList, for example) might very well have a length
> property that shows up in the body of a for in loop. There is no
> standard that specifies one way or another if a NodeList's length
> property should be enumerable. I can't see why anyone would care,
> either.
>
> javascript: for(var p in document.childNodes) if(!isFinite(p)) alert(p);
>
> Firefox 3.5, Safari 4, Chrome 2:
>    "length"
>    "item"
>
> Opera 10:
>    "length"
>    "item"
>    "namedItem"
>    "tags"
>
> IE7
>    "tags"
>
> That example alone shows a few good reasons why using a for in loop
> would be a bad choice. In superficial testing in a few browsers, the
> length property showed up in the body of a for in loop. Other
> properties will show up, depending on the implementation and property
> name. Other collections will likely have even more properties.
>
> if a DOM collection is considered arrayLike, then using for in loops
> over arrayLike can be considered to be a reckless, error-prone
> concept.
>
> OTOH, If indexed properties are got off the object, as with your
> standard for loop, the enumerability of - length - is irrelevant. So
> again: Why do you care if |length| is enumerable?
>
> Garrett
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
   Cheers,
   --MarkM
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to