Should host objects be able to have [[Class]] "Function", "Array" etc.?

Brendan Eich brendan at mozilla.com
Wed Nov 19 11:28:08 PST 2008


On Nov 19, 2008, at 6:08 AM, Maciej Stachowiak wrote:

>> I also don't see a problem with David-Sarah's suggestion of  
>> forbidding host objects from having [[Class]] "Function". Most  
>> places in the spec care only about whether something is callable  
>> (has a [[Call]] property), not whether it has [[Class]] "Function".
>
> It seems arbitrary to me that functions implemented in native code  
> ("internal functions" in ECMA-262 terms) that are part of the  
> ECMAScript spec must have the [[Class]] "Function", but any that are  
> not specified there (and are perhaps specified elsewhere) would be  
> required not to have [[Class]] "Function". Why should Math.random be  
> required to have [[Class]] "Function", but document.getElementById  
> or Math.myImplementationExtension be required not to? Do you really  
> think it makes sense to determine whether something is a function by  
> whether it is mentioned in the ECMAScript spec?

That's silly, not only because of inclusion or location in spec being  
immaterial, but also because of gratuitous differences between host  
and native implementations even assuming the partitioning between them  
is fixed forever.

It does seem worth addressing the variation among browsers where IE's  
alert is not a function -- has typeof-type "object" -- while it is  
"function" and has [[Class]] "Function" by all measures in other  
browsers I'm familiar with. This is considered an IE misfeature, AFAICT.

The original Netscape 2 implementation I did in 1995 wrapped the same  
function clothing around native and "host" functions.

Does anyone know of other DOM implementations that differentiate  
detectably between host and native functions? Excluding exceptional  
cases such as Mozilla's LiveConnect proxy objects that represent  
overloaded Java methods, e.g.


> (Note also that Math.random has [[Class]] "Function" but not a  
> "prototype" property.)

Yeah, that's something I missed in ES1 days, which must have come from  
JScript. The original Netscape JS implementation then, and  
SpiderMonkey still,  both give native functions .prototype properties  
(bug https://bugzilla.mozilla.org/show_bug.cgi?id=445319).

/be


More information about the Es-discuss mailing list