Re: Non-constructible constructors and Arrays

On 7/27/11, Brendan Eich <brendan@mozilla.com> wrote:
> On Jul 27, 2011, at 10:32 PM, Garrett Smith wrote:
>
>> On 7/27/11, Alex Russell <slightlyoff@google.com> wrote:
>>> The topic of WebIDL's last call just came up at the TC39 face-to-face,
>>> and one issue I've flagged but not posted here yet is the topic of
>>> non-constructible constructors. Section 4.3.5 contains an explicit
>>> example of a behavior that I'd like to see repaired:
>>>
>>>    // from: http://www.w3.org/TR/2011/WD-WebIDL-20110712/#Constructor
>>>    var z = new NodeList(); // This would throw a TypeError, since no
>>>                                          // [Constructor] is declared.
>>>
>> Existing browser behavior seems fine by me.
>
> Hi Garrett -- the issue isn't breaking existing behavior, it is extending it
> so you can "new" a NodeList. Is there a reason not to do this? Regularity in
> languages and APIs is better than irregular and seemingly arbitrary
> restrictions, all else equal.
>
What can a program do with `new NodeList()`?

Then also the problem with changing global Event, as I explained.

>
>>> On the topic of Arrays, I know it has come up before that there are
>>> DOM collection types, in particular NodeList, which should be Array
>>> subclass instances.
>> The problems with that were quickly uncovered on:
>> "[whatwg] Adding ECMAScript 5 array extras to HTMLCollection"
>
> You mean the thread containing your message:
>
> http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2010-August/027668.html
>
> It's hard to tell what problems you mean, apart from browser differences
> that would be fixed by specifying better normative behavior, via WebIDL and
> relevant DOM and Web API specs. I mean, sure -- some browsers don't do the
> right thing with array generics on NodeList. This is not a reason to reject
> the idea of extending NodeList's spec (implementations to follow) so the
> generics work.
>
Well in this case, the proposal is technically speaking not to extend
NodeList but to re-design it so that it inherits from (extends) Array.
And fine, whatever, but what was brought up in that thread is the
questions of what do the methods do, e.g. given a nodeList that in a
document, what would aCollection.reverse() do, for example?
-- 
Garrett

Received on Thursday, 28 July 2011 14:28:25 UTC