ES6 doesn't need opt-in
Mark S. Miller
erights at google.com
Wed Jan 4 15:56:19 PST 2012
Hi Brendan, I agree with most of your message, so only commenting on the
On Wed, Jan 4, 2012 at 12:52 PM, Brendan Eich <brendan at mozilla.com> wrote:
> > - After Dave's posting I foresaw people wanting implicit opt-in with
> > other constructs, e.g. classes or uses of `import' -- and voila, we're
> > already there. But even with that, you still have to rely on explicit
> > opt-in (via "use strict"?) for enabling some features elsewhere.
> Which features?
Lexical scoping (top level aside of course). Encapsulated functions. Sane
arguments. Poisoning of .caller, .callee, .arguments. Ability to write code
that continues to run on old browsers and to run sanely on old ES5
browsers. Throw errors on failed assignment rather than silently continuing
as if everything is fine. Throw exception on a failed delete. Throw on
assigning to an undefined variable rather than having misspelling silently
create a new global. Preventing an eval from corrupting its caller's
scope. Need I go on? Compared to ES5 strict, ES5 non-strict is insane.
Regarding adoption of strict, another audience we should keep in mind is
strict"; or teach them to program in a language without sane scope rules or
encapsulated functions, and with silent errors?
No -- "use strict"; the string literal expression-statement is meaningless
> pre-ES5, ES5-strict in ES5, and redundant in Harmony code.
I don't see how it can be redundant in harmony code. Say I write a script,
intending it to be harmony, but which doesn't begin with "class", "module",
"function*", or whatever else we decide is a new opt-in. But I want the
code above the first, say "module", to still obey harmony rules rather than
non-strict rules. I would still need to say something else at the top of
the script to ensure this.
> (BTW I still think we want a real |use strict;| pragma, to choke old
Yes. Crock suggested this in the old ES5 days and I think it is still a
"use strict"; // still runs on old browsers, but non-strictly
use strict; // causes an early error on old browsers.
Had we adopting it into ES5, it would have this meaning clearly. It may
still be a good idea, but consider the new complexity. Now the second form
also causes an early error on old ES5 browsers, where the script might
otherwise have been able to run strictly.
> Now what do you say?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss