reformed with

Brendan Eich brendan at
Mon Feb 5 17:06:41 PST 2007

On Feb 4, 2007, at 6:45 PM, Yuh-Ruey Chen wrote:

> Lars T Hansen wrote:
>> In practice your object would probably be of some named type, so you
>> would
>> really do something like this:
>>      with (this.DOMTable : domtable_t) {
>>          ...
>>      }
>> Whether you define domtable_t yourself or the environment defines it
>> for you,
>> having named types makes reformed with (as well as most uses of the
>> structural
>> type system) much more pleasant.
> Ah, thanks for the clarification. That does makes reformed with much
> more appealing. It would help if this was mentioned in the proposal in
> prose :)

It's a given when you read the whole spec that structural types can  
have names, via the 'type T = ...' declaration or the embedding host.  
But yeah, could be repeated here.

> Although if the environment doesn't define the types for host objects,
> or at least typeOf(host_object), it would be a large hassle... (typeOf
> is the function to get the type of an object, right?)

intrinsic::typeOf -- see 
meta_objects.html. Note well that this is an optional reflection  
library, not guaranteed to be present in all ES4 implementations.

It may or may not be a hassle to name or  repeat a structural type,  
but if you are migrating old code or dealing with the persistence of  
with, and you want to avoid severe deoptimization, reformed with  
gives you a way at lower cost than rewriting to eliminate the with.

>> If you need a subset view on the object (with access to other
>> variables outside
>> the with having the same name as properties of the object) then I
>> agree with
>> you, reformed with is cumbersome and most people would not use it,
>> unless
>> the subset view could be named and used several places.
> Hmm...this should never be the case when revising an ES3 with  
> statement.

Why not? I can recall ES3 (ES1, or JS1 would be more accurate) code  
that thinks it knows what x means in a with body, but is sometimes  
unpleasantly surprised. A subset view would help fix bugs while  
migrating this old code.

>> I agree.  At the last committee meeting we discussed putting some
>> restrictions
>> on classical "with" in strict mode (though the minutes do not  
>> record any
>> conclusions).  If we were to do that, however, the reformed with
>> might fare
>> better.
> Do you mean that in strict mode, |with(o)| would be translated to
> |with(o:typeOf(o))| where typeOf(o) is determined at compile-time? If
> so, that would be nice.

Not sure what Lars meant, but I saw something like that and found it  
attractive at first. However, intrinsic::typeOf(o) is a runtime  
expression, as well as a call to an optional library function.  
Imputing it here in the case of with-under-strict-mode is unusual and  
something TG1 members seem to be against, but we're still debating.

> Would there be any possibility of using something similar for standard
> mode? |with(o:typeOf(o))| would be incompatible with |with(o)| in
> standard mode, but it would be nice if there was a shortcut syntax for
> the former. In the above example, it would be nice to do
> |with(this.DOMTable:<something>)| instead of
> |with(this.DOMTable:typeOf(this.DOMTable)| (although on the other  
> hand,
> I'm not a fan of adding a new syntactic construct for a possibly
> uncommonly used feature).

There's no reason for any of this given reformed with (http://


More information about the Es4-discuss mailing list