W3C home > Mailing lists > Public > public-script-coord@w3.org > October to December 2012

Re: [WebIDL] Would it make sense to add annotations for "creates a new object each time" and "always returns the same object"?

From: Jonas Sicking <jonas@sicking.cc>
Date: Tue, 23 Oct 2012 15:44:40 -0700
Message-ID: <CA+c2ei_xMcr2y0eu-3MskKjt51_fwsn4rG4hOxqj4OwTgZ4FQA@mail.gmail.com>
To: Ojan Vafai <ojan@chromium.org>
Cc: Boris Zbarsky <bzbarsky@mit.edu>, Glenn Adams <glenn@skynav.com>, "public-script-coord@w3.org" <public-script-coord@w3.org>
On Mon, Oct 22, 2012 at 10:33 PM, Ojan Vafai <ojan@chromium.org> wrote:
> On Mon, Oct 22, 2012 at 8:08 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
>>
>> On 10/22/12 9:24 PM, Ojan Vafai wrote:
>>>
>>> Obviously, there's nothing we can do about legacy APIs, so it might
>>> still make sense to add the annotation even if we decide that methods
>>> should always return a new object.
>>
>> Having methods always return a new object is silly, imo.  Consider a
>> method like getElementById.  How would it make any sense for it to always
>> return a new object?
>
> Good point. That would be silly.

Yes, it seems like functions are very case dependent.

However I agree that attribute getters in general should be returning
the same object. So obj.attr === obj.attr should in general return
true. Though I suspect that there are several cases where changing the
object state will also change what object it returns. So

obj.attr === obj.attr;  // Generally true
x = obj.attr;
obj.someFunc(...);
x === obj.attr;  // Can go either way.

Node.firstChild would be a good example of this.

/ Jonas
Received on Tuesday, 23 October 2012 22:45:37 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 May 2013 19:30:07 UTC