Re: Do array types have public interface objects?

David Flanagan:
> The WebIDL draft specifies that an array type such as Attr[] (used
> by the DOM Core Element.attributes attribute) has the name
> "AttrArray" but it doesn't seem to require that there be an
> AttrArray interface object in the global scope as it does for
> regular interfaces.

Type names (“AttrArray” in this case) are used only in two cases, which
both happen to be related to array types), currently: one is as the
[[Class]] value for array host objects, and the second is as the name of
the Java array interface for an array type.

You’re right that interface objects for array types aren’t required to
exist.

> On the other hand, instances of AttrArray don't inherit directly
> from Array.protoype.  Instead there is an array host object
> prototype object on the inheritance chain before Array.prototype.
> This suggests to me that perhaps the intent (not yet codified in the
> spec) is that this prototype object should be accessible as
> AttrArray.prototype.

Maybe it should be.  But maybe we should just remove array host object
prototype objects altogether.  They were introduced initially because
they had on them a copy of the Array.prototype properties that made
sense for array host objects, but now it’s just empty since we inherit
directly from Array.prototype.

> As it stands now, if you want to define a property to be inherited
> by AttrArrays (and only AttrArrays) you'd have to first obtain an
> instance of AttrArray and use Object.getPrototypeOf() on it, which
> seems awkward.

Yeah.

> If individual array types can be individually monkeypatched, then I
> think they deserve a public interface object.  On the other hand, if
> they don't have a public interface object, then wouldn't it be
> simpler to have them inherit directly from Array.prototype?

I think that’s the way to go.

-- 
Cameron McCormack ≝ http://mcc.id.au/

Received on Monday, 20 June 2011 22:12:59 UTC