Re: [Bindings] What does typeof return for interface objects?

On Mar 18, 2008, at 11:06 PM, Cameron McCormack wrote:

>
> Travis Leithead:
>> I can think of some interesting use cases for implementing [[call]]
>> on an interface object... I'd prefer to leave it unspecified at best.
>
> OK.
>
>> I agree with Hixie on the point of specifying the behavior of typeof,
>> and to me typeof HTMLDocument == 'function' makes sense, since I  
>> think
>> of these as 'constructor objects' (even if they don't allow object
>> construction in some cases).
>
> But if you want ‘typeof HTMLDocument == 'function'’, then you would
> need to mandate [[Call]] being implemented on the interface object,
> since ECMA-262 says that the typeof operator returns 'function' only  
> if
> the object implements [[Call]].  And then if you require [[Call]] to  
> be
> implemented, then you’d need to say what that function would do.

ECMA-262 actually allows typeof to return anything at all for host  
objects (which all of the DOM binding objects are). So it would not be  
an ECMA-262 violation, technically, for an uncallable object to give  
typeof == 'function', but I do think it would be a bad idea.

In WebKit we currently follow the ECMA-262 callability-based approach  
even for host objects, but not all web engines do. For example, I  
believe that in Trident, NodeLists are callable but give a typeof  
result of 'object' instead of 'function'.

Regards,
Maciej

Received on Wednesday, 19 March 2008 07:08:44 UTC