instanceof Operator

Brendan Eich brendan at mozilla.org
Mon Oct 22 11:16:55 PDT 2007


On Oct 22, 2007, at 4:53 AM, P T Withington wrote:

>> String has its uses, not just embedded in content that requires
>> compatibility: string and String inter-convert, String is non-final,
>> and the two share a prototype object.
>
> I think Dylan would have made String an open subclass of the sealed
> class string: http://www.opendylan.org/books/dpg/db_305.html

We can have dynamic subclasses of non-dynamic classes, but if String  
<: string, then string can't be final, which precludes some  
optimizations and (separate) simplifications. We think these matter  
enough not to make String <: string.

Such a relation would also be "upside down" by comparison to ES1-3,  
where the primitive string type is not an object type, and even if  
you pretended it were, it would not be superior to, or more general  
than, String (in any prototype-based or class-based sense). Exactly  
the opposite is true: String is more general than string.

>> In ES4, string has catchalls to satisfy this ephemeral wrapper get/
>> set compatibility, but method calls on string instances do not
>> require String wrapper creation.
>
> Are you saying for compatibility you have to maintain this 'ephemeral
> wrapper' behavior?

Yes. The use-case is generic programming over string primitives and  
bona-fide ES3 objects: you want to allow "hello" to flow into a  
function farble(x) that gets and/or sets ad-hoc properties on x,  
without exceptions being thrown. Such a function can't count on  
getting what it set, of course (ephemeral wrappers). But it must fail  
soft as it has for going on 12 years.

> My use case is for an annotated string, the result of a sprintf-like
> formatter that remembers the objects associated with each
> representation (so you can inspect a message for more detailed
> information):  http://svn.openlaszlo.org/openlaszlo/trunk/WEB-INF/lps/
> lfc/debugger/LzMessage.lzs

Looks like it should derive from String and be happy in ES4. I'll  
take a closer look later today.

/be




More information about the Es4-discuss mailing list