On 16.04.2011 0:59, Sam Tobin-Hochstadt wrote:
On Fri, Apr 15, 2011 at 4:53 PM, Mark S. Miller<[email protected]> wrote:
I understand how dynamic scope works. And ES5 with the mutable global
object has it:
function bar() { return foo };
bar() // error: foo is not defined
var foo = 7;
bar(); // produces 7
Lexical scope would produce the error both times.
Hi Sam, this does establish that ES5 does not have lexical scope. But I
don't how ES5 has dynamic scope. In the above example, the 'foo' that bar
has in scope during the second call still has nothing to do with what's in
scope at the call site from which bar is called.
I think what you're saying is that if I then do:
(function (){ var foo = 8; return bar(); })();
I'll get 7, not 8, which is certainly true. We can think of this as
dynamically scoped with respect to "top-level" variables, ie those
bound at the top level or unbound at the time of definition, or we can
think of this as a variety of scoping that is
neither lexical nor
dynamic -- that's just a terminology question.
A "runtime scope augmentation" which still keeps the lexical scope (of
functions in particular and mainly). But, yeah, I agree that we go into
terminology discussion which is not the best.
Let's agree on this: of course lexical bindings addressing is the best
in respect of (a) optimized identifiers lookup and (b) having these
errors as compile-time, not runtime, but (2) we lose the ability to
expressively define some bindings. Is this approach correct now? ;)
Dmitry.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss