String finality (was: Re: ARGUMENTS.SHOULD.BE.ARRAY bug-fix)

Brendan Eich brendan at
Mon Mar 19 13:49:14 PDT 2007

On Mar 19, 2007, at 1:01 PM, zwetan wrote:

> but still out of curiosity,
> in a case where someone would want to do the same kind of methods  
> delegation
> but with non-generic methods (this value required to be of the  
> original type)
> does ES4 offers some way of doing it ?

Bound methods cannot be called on a |this| parameter of the wrong  
type -- they carry their |this| around once extracted (e.g. from a  
class instance).

> I'm thinking of reusing Date methods for examples in a "new" classes
> like DateTime, TimeSpan, etc...
> but Date methods require that the this value be the Date Object.

You can't do this today, and it won't work in ES4.

> or another ex, like trying to inherit from the class String on the  
> prototype

But String's methods are all generic, except for toString and  
valueOf, so you could reuse String's generic methods in several ways  
(by extracting references to them or their static counterparts; by  
subclassing String -- see below; by one-off delegations via .apply or  

> cf
> class String2
>     {
>     prototype = new String();
>     //etc...
>     }
> I know that String is final,

String is final in AS3, but not final in proposed ES4 as of the last  
face-to-face meeting.

Here is the latest plan of record for primitive (string) vs. wrapper  
(String) types:

* Suppose we support primitive types via final class string!, etc.,  
and model wrapping as follows:
     * class string! extends String.
     * The fixed methods of the final primitive class are all  
intrinsic only, not prototype.
     * Which implies that the standard methods of String are only  
prototype [at the time this was written, intrinsic => final -- we are  
revisiting, but backward compatibility does not require intrinsic  
methods in String. /be].
     * Thus we split intrinsic functionality from String and push it  
down into string.
     * “hi”.charAt(0) therefore invokes String.prototype.charAt on  
the string “hi” in the absence of a 'use namespace intrinsic'.
     * If you want speed and not AOP, 'use namespace intrinsic' or  
call “hi”.intrinsic::charAt(0) (or in this case, use indexing).
     * To support “hi”.nosuch === undefined and “hi”.foo = 42 where a  
subsequent "hi".foo results in undefined, we use Jeff’s catchalls  
suggestion [defining get *() {...} and set *() {...} on class  
string], which simulates ES1-3’s wrapping under ToObject
     * Code may freely use string and unless it explicitly uses  
intrinsic, AOP via String.prototype still works.
     * And (thanks to the catchalls) generic get-and-test-against- 
undefined (or equivalent) and useless sets still work.

This applies to boolean/Boolean too. Number is different, given the  
several primitive types (int, uint, double, decimal). I'll defer  
getting into Number and let people digest the above.


More information about the Es4-discuss mailing list