- From: Garrett Smith <dhtmlkitchen@gmail.com>
- Date: Fri, 29 Jul 2011 20:29:25 -0700
- 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) {
arraySlice.call(nodeList);
}
// Remove `if` statement.
arraySlice.call(nodeList);
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.
--
Garrett
Received on Saturday, 30 July 2011 03:30:00 UTC