How to escape implicit 'with (this)' of a method body
dherman at ccs.neu.edu
Thu Jul 31 04:52:32 PDT 2008
>> 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.
> I guess this is considered a small penalty to pay in exchange for
> adding the magical instance scope to methods (which O-O programmers
> seem to expect these days). Something we'd regret more if we had
> multi-methods, perhaps...
We should take this problem seriously. OO programmers expect dynamic
dispatch, but not dynamic scope! In OO languages with static type
systems, you can tell when a variable reference is being dynamically
dynamic dispatch is happening because the `this.' prefix is always
required. But now with classes, since we don't have a static type system
to know whether a dynamically inserted property might shadow a lexical
reference, dynamic scope has slipped in.
Dynamic scope is very bad.
Another solution is to require the `this.' prefix even inside classes,
just as they are required everywhere else, so you can distinguish
between a dynamically referenced variable and a lexically referenced
variable. I think Python (a more-or-less lexically scoped but
dynamically typed OO language) requires this? (Pythonistas please
correct me if I'm wrong.) If five characters are really too hard to
write, there's always the possibility of the `.foo' shorthand syntax.
More information about the Es4-discuss