2 ms·
`with` is still lexically scoped—it just adds another scope to the lexical scope chain. The variables are still scoped to the beginning and end of a particular
by lolinder 3y ago
`with` is still lexically scoped—it just adds another scope to the lexical scope chain. The variables are still scoped to the beginning and end of a particular block of code, and if that code calls out to a function that was defined outside of that block the variables don't follow to that called function (unless explicitly passed as arguments).
From what I can tell, your CL example is truly dynamically scoped (assuming the global is defined with `defvar`)—functions defined outside of that `let` form will still use the version you give in the `let` when they're called inside that call tree.
Where JavaScript does have a bit of dynamic scoping is with `this`. All OOP languages technically use dynamic scope for `this`, but JavaScript even more so since `this` can be rebound arbitrarily.
- kazinator 3y agoIf with defines variables which are not mentioned in it explicitly, and which are controlled by an entirely different part of the program, possibly in another file, we can make the argument that it is not actually lexically scoped.