[whatwg] Adding ECMAScript 5 array extras to HTMLCollection
oliver at apple.com
Mon Aug 2 09:51:22 PDT 2010
On Aug 2, 2010, at 7:36 AM, And Clover wrote:
> On 07/30/2010 06:43 AM, Oliver Hunt wrote:
>> all array functions defined in ES5 are "generic" in that they work
>> over any array-like object.
Uhhh, I have no idea what you're talking about -- there are no type checks in any of the array prototype functions, they all operate in terms of property access alone, all the methods we're talking about basically start out like this:
1. Let O be the result of calling ToObject passing the this value as the argument.
2. Let lenValue be the result of calling the [[Get]] internal method of O with the argument "length".
3. Let len be ToUint32(lenValue).
4. If IsCallable(callbackfn) is false, throw a TypeError exception.
5. If thisArg was supplied, let T be thisArg; else let T be undefined.
6. Let k be 0.
7. Repeat, while k < len
Eg. "array-like" in the context of ES5 should be interpreted as "has a property named 'length', the array methods will work on any type.
> FWIW in practice `Array.prototype.*.call(htmlcollection)` does work on the modern desktop browsers except for IE.
> It would be possible to specify that the native-JS object guarantee should also extend to node lists. This would allow fast browser implementations of the array-like methods to be used without having to copy to a new Array. However this would still leave the method of calling them a little ugly.
As above there is no question of it being possible -- the spec behaviour makes no exceptions for host vs. native object types. If IE has a bug, then IE has a bug, that doesn't change the spec.
More information about the whatwg