How to escape implicit 'with (this)' of a method body

Brendan Eich brendan at
Mon Jul 28 22:19:58 PDT 2008

On Jul 28, 2008, at 10:05 PM, Jon Zeppieri wrote:

> Isn't the 'with' statement in the original example significant?  In
> the general case, assuming that you don't know what properties 'this'
> has (as it may have dynamic properties in addition to the fixtures
> determined by its class), you have no way of knowing whether 'global'
> or 'window' refers to the global object or to some arbitrary property
> of 'this.'

The original code used "without (this)", not "with", which I took to  
mean "avoid instance properties shadowing globals". If you read the  
original as "with", then there is no such problem. But if you  
construct a problematic case using 'with' and dynamic properties,  
then I concede that 'global' could be shadowed. This is a reason to  
avoid 'with'. In the ES4 proposals last sent out, you could always  
use __ES4__::global if you really wanted to avoid conflicts -- unless  
someone perversely added '__ES4__' as a dynamic instance property.

There's no solution to this problem other than reserving at least one  
name, and we can't do that compatibly. We could reserve __ES4__ in  
version-selected ES4 mode, but that seems unnecessary.


More information about the Es4-discuss mailing list