Re: Non-constructible constructors and Arrays

On 7/28/11, Allen Wirfs-Brock <> 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