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

Re: Non-constructible constructors and Arrays

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Fri, 29 Jul 2011 20:29:25 -0700
Message-ID: <CABZUbM1MP6SrG8qLhdjJSQ+RNGo8P2ktfPQxRotKZk96S8NX-A@mail.gmail.com>
To: Allen Wirfs-Brock <allen@wirfs-brock.com>
Cc: Jonas Sicking <jonas@sicking.cc>, Alex Russell <slightlyoff@google.com>, public-script-coord@w3.org, Brendan Eich <brendan@mozilla.com>, Cameron McCormack <cam@mcc.id.au>
On 7/28/11, Allen Wirfs-Brock <allen@wirfs-brock.com> wrote:

>> The only reasonable thing we could do is to make all mutating
>> operations throw, which frankly would be a pretty strange API. I.e.
>> all NodeLists would have whole host of operations like .push and
>> .shift which always would throw. It would seem much better if those
>> operations weren't there.
> Such an implementation would be no different from what happens if somebody
> does something like:
> var aReadOnlyArray = Object.freeze([1,2,3,4,5,6,7,8,9,10]);

> The methods that would throw an exception are:

Useful. Feature-testible. Fallback is possible, though just using the
falback would result in wider compatibility, e.g. instead of :

if(!nodeList.slice) {

// Remove `if` statement.

And for those who are thinking:-
if(!NodeList.prototype.slice) {
  NodeList.prototype.slice = ...

That sort of thing has historically been the source of a lot of problems.

Good post.
Received on Saturday, 30 July 2011 03:30:00 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:04 UTC