Re: [WebIDL] interface objects with [Constructor] and [[Call]]

On Fri, Jun 11, 2010 at 3:15 PM, Maciej Stachowiak <mjs@apple.com> wrote:
>
> On Jun 11, 2010, at 3:05 PM, James Graham wrote:
>
>> Quoting Travis Leithead <travil@microsoft.com>:
>>
>>> The way I interpret that, [[Call]] should equal [[Construct]] in all  cases for host objects. Why? Because real-world code using  XMLHttpRequest today mixes and matches the invocation pattern:
>>>
>>> 'new XMLHttpRequest;'
>>> 'new XMLHttpRequest();'
>>> 'XMLHttpRequest();'
>>>
>>> and for web-compat, we want all of these to succeed.
>>
>> Arguably the XMLHttpRequest spec special cases this so all three forms
>> work at [1] (I am not sure what exactly is meant by "constructor is
>> invoked" here since it could mean "[[Construct]] method is called" or
>> "[[Call]] method is called"; this should probably be clarified in the
>> spec). Therefore that is not a good example from which to derive a
>> general rule.
>>
>> On general principles I would prefer [[Call]] === [[Construct]] for
>> new host object constructors; it seems closest to the behaviour of
>> ECMAScript builtins and convenient for authors, but for legacy
>> constructors we probably need to mimic deployed UA behaviour.
>
> Another possibility when there are no legacy constraints is to not implement [[Call]], so that there is only one way to invoke the constructor. For vanilla JS functions, calling them with and without "new" has quite different behavior. And for many builtins, calling with and without "new" actually does subtly different things. Thus, I don't think we want to encourage developers to mix and match.

Agreed. I was quite surprised to find out what "XMLHttpRequest()"
does. I had not expected that to work at all. I suspect other people
would be in a similar situation.

/ Jonas

Received on Friday, 11 June 2010 22:24:53 UTC