I've noticed that there are at least two uses of dynamic scope, all maledictions (and so tending to blur together into one general curse):
* Using the dynamic link or call stack as scope chain link (clearly evil; er, eval ;-). * Having a scope chain element be a mutable object in which bindings can come and even go (also bad, and the issue here in ES5 non-strict and older JS). We could try to call the latter "dynamic binding", but "binding" is so horribly overused and overloaded informally... Not sure this helps :-(. /be On Apr 15, 2011, at 10:59 PM, 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. > -- > sam th > [email protected] _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

