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.
--
sam th
[email protected]
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss