Re: Getters establish own properties, or why is [NamedPropertiesObject] discouraged?

On 2/24/12 9:20 PM, Garrett Smith wrote:
> On 2/24/12, Boris Zbarsky<bzbarsky@mit.edu>  wrote:
>> On 2/24/12 1:05 PM, Garrett Smith wrote:
>>> No, using getter/setter instead does not mean that the properties are
>>> "own".
>>
>> Per current webidl spec, defining a "getter" or "setter" on the
>> interface does mean the properties involved are own properties.  Please
>> see the spec.
>>
> What implementation does that?

For the cases that are getter/setter in idl?  I believe at least 
Trident, WebKit/V8, WebKit/JSC, and Gecko.  I haven't tested Presto, but 
I wouldn't be surprised if it does too.

>>> In fact, it is often the case where an object's getter or
>>> setter resides on the prototype chain. For example, the style
>>> property, in Gecko is a getter on the prototype chain:-
>>>
>>> document.body.hasOwnProperty("style");.
>>
>> That's not a "getter" in the IDL.
>>
> I didn't say it was. That line of code shows that `document.body` does
> not have an own `style` property.

Yes, of course.

> The reason for showing that is to
> demonstrate that 1) The element has a style property, 2) that it is
> not an /own/ property, and 3) that it is implemented as a getter

Sure.

>> Try something more like this:
>>
>>     <body name="foo">
>>     <script>
>>       alert(document.getElementsByTagName("body").hasOwnProperty("foo"));
>>     </script>
>>
> What's that supposed to show?

That properties that are defined as "getter" in IDL (which this one is) 
are own properties of the object (in this case of the list object 
returned by getElementsByTagName).

I think you're confusing the concept of "property implemented by a 
getter" and "property defined as 'getter' in the IDL".  Lots of things 
are the former but not the latter.

-Boris

Received on Saturday, 25 February 2012 02:27:57 UTC