reformed with

Yuh-Ruey Chen maian330 at gmail.com
Sun Feb 4 18:45:16 PST 2007


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 :)

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?)

> 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.

> > There's also the argument of discoverability. Script authors are  
> > likely
> > to learn the new let syntax since it can be used pretty much anywhere.
> > The reformed with syntax, on the other hand, is a bit obscure. If a
> > feature isn't that discoverable and there's an alternative feature  
> > that
> > is and is just as good, I'd say drop the less discoverable feature.
>
> 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.

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).

-Yuh-Ruey



More information about the Es4-discuss mailing list