Re: HTMLCollection item() vs. namedItem() with [] syntax (detailed review of the DOM)

On Fri, Jul 25, 2008 at 8:15 PM, Cameron McCormack <cam@mcc.id.au> wrote:
>
> Hi Garrett.
>
> Garrett Smith:


>> Any assumption that there is a modified [[Get]] for the collection
>> would be wrong.
>
> I see.  If we want to specify that (that they are real properties that
> exist on the object),

Whatever you do, definitely do not document something as being other
than what it actually is in implementations.

> then I think it will be hard for Web IDL to
> provide some syntactic description of this behaviour.

Why are you trying to document EcmaScript [[Get]] in IDL? EcmaScript's
[[Get]] and property access operators are language specific to
EcmaScript, are clearly defined, and don't have the same meaning in
other bindings.

[[Get]] resolves a property on an object (up through the prototype
chain) and returns its value or undefined.

Identifier[ <property-name-string> ]

document.body.childNodes["0"]
document.body.childNodes["item"]

document.body.childNodes.0 - is not valid syntax, so the other
property access operators must be used.

http://google.com/search?hl=en&q=javascript+property+access+operator

> So it would then
> be up to HTML to state that properties get created and removed when
> elements are added and removed from the document.
>

That seems to be a mistake. It can be clearly demonstrated that at
least 3 implementations, Safari3, Firefox4, and Opera9 implement
property access of a collection in an XMLDocument.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>XML Document</title>
</head>
<body>
<script type="text/javascript">
alert(document.childNodes[0].nodeName);
</script>
</body>
</html>

Would it be bad to specify it in the EcmaScript bindings as an
optional feature, and just make a small note about it? e.g.
"Implementations MAY implement create numeric properties of the
collection which may be then accessed via property access operator, in
lieu of item()"

?

This would leave explaining [[Get]] to the relevant language
specification (Ecma-262)

It would probably be OK to omit the details of where on the prototype
chain these properties exists or what attributes they have (if the
items are ReadOnly, DontDelete, et c).

Garrett

> --
> Cameron McCormack

Received on Saturday, 26 July 2008 04:32:47 UTC