Andreas Rossberg wrote:
What I mean is that in a model with mutable scope (or worse, the
global object) _declarations_ themselves become global effects. Later
conflicts can affect all code that has been loaded _before_, e.g. by
smashing over an existing binding.
I get it, but this is just "the way JS works" for var and function
declarations at top level. For example, people have figured out how to
use var for object detection without violating strict mode by creating a
global variable by assignment.
Adding let/const/class at top level either:
1. Adds a "second way JS works" (either your favored counter-proposal,
the ML-like nested scopes; or the one Saam favored that Allen likes,
where each script has an implicit {} around its body as far as those
declarations -- but not function -- are concerned; or something else).
or:
2. Works by analogy to var (and doesn't bother with TDZ and other
peculiarities of bindings in ES6).
My point is (2) doesn't add to the top level model-set, ignoring common
complexities of const and class. It just equates let and var. This has a
cost too, I agree, but there's no cost-free solution.
Perhaps Allen's point about
<script>
var Widget = class {...}
</script>
is better from a certain point of view (Crockford advocates var f =
function(){} over function f(){}, IIRC, in JS:TGP), but I would bet lots
of real money that ES6 users would be bummed to learn that they cannot
declare classes (or consts) in one script and use them in the next.
Your nesting counter-proposal allows that, cleverly, but at the cost of
another model. The only proposal that doesn't require thinking in a new
"second" way for the common cases of class, let without TDZ actually
firing, const without TDZ or non-initialiser assignemnt, is the one
Jason favored in the o.p.
/be
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss