ES6 doesn't need opt-in

Allen Wirfs-Brock allen at
Thu Jan 5 09:30:24 PST 2012

On Jan 4, 2012, at 11:38 PM, Mark S. Miller wrote:

> In your suggestion, when an occurrence of destructuring (or any other new syntax) is seen, what unit of code is then opting in to strict? Would it be the nearest enclosing function, module, class, generator, or Program? I think I'm warming to the idea.
> I think having the opt-in unit be the destructuring pattern and everything recursively contained within it would be a bad idea. In this regard, destructuring is a different category of opt-in by new syntax than is module, class, and generator.

This first came up in the context of formal parameters that use destructuring (or default value initializers, or rest).  In that case, the idea was that this would imply that the function with those parameters is a "strict" function.

Whether  the use of destructuring (or rest/spread) in declarations or expressions within the body of the function also implies a "strict" function is potentially a separate issue. However, I  think we need to keep things as simple and consistent as possible so on that basis perhaps they should also imply a strict function.  In neither case, were we thinking of restricting the strictness to just the destructuring pattern itself.

A slightly different approach to this might be to say that the use of any new syntax implies that the immediately surrounding function or program is in strict mode.  In other words, the default is strict mode unless the code exclusively uses ES5 syntactic constructs.


More information about the es-discuss mailing list