W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2011

Re: Move length property to the set of supported property indicies?

From: David Flanagan <dflanagan@mozilla.com>
Date: Fri, 20 May 2011 15:56:32 -0700
Message-ID: <4DD6F1A0.4070404@mozilla.com>
To: public-script-coord@w3.org, Boris Zbarsky <bzbarsky@MIT.EDU>
Boris wrote:
> While I agree that having length be an own property is somewhat easier
> to implement, the fact that it would then behave totally different from
> all the other "non-live" DOM properties seems like a bad thing for
> _authors_.

In this case, I disagree, since it would make NodeList and other 
array-like collections more like arrays:

[].hasOwnProperty("length")  => true

I suspect that authors would expect the length property to behave just 
like the array index properties with which it is intimately related.
> One other note... Why is this an issue for length but not, say, item()
Conceptually, because length just seems to go with the array index 
properties.

 From an implementation standpoint, once I have a proxy that handles the 
array index properties, I can implement item(n) like this without having 
to use a WeakMap:

NodeList.prototype.item = function(n) { r = this[n]; if (r===undefined) 
return null; else return r; };

      David
Received on Friday, 20 May 2011 22:57:01 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:03 UTC