我还不熟悉 ECMAScript 6。我刚刚克隆了 React Starter Kit repo,它使用 ES6 编写应用程序代码。我惊讶地发现 linter 是 configured禁止出现 use strict
指令,我认为这是在 ES6 之前的 JavaScript 中推荐的。那有什么意义呢?
最佳答案
ES6 模块始终处于严格模式。引用the spec的相关部分:
10.2.1 Strict Mode Code
An ECMAScript Script syntactic unit may be processed using either unrestricted or strict mode syntax and semantics. Code is interpreted as strict mode code in the following situations:
- Global code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive (see 14.1.1).
- Module code is always strict mode code.
- All parts of a ClassDeclaration or a ClassExpression are strict mode code.
- Eval code is strict mode code if it begins with a Directive Prologue that contains a Use Strict Directive or if the call to eval is a direct eval (see 12.3.4.1) that is contained in strict mode code.
- Function code is strict mode code if the associated FunctionDeclaration, FunctionExpression, GeneratorDeclaration, GeneratorExpression, MethodDefinition, or ArrowFunction is contained in strict mode code or if the code that produces the value of the function’s [[ECMAScriptCode]] internal slot begins with a Directive Prologue that contains a Use Strict Directive.
- Function code that is supplied as the arguments to the built-in Function and Generator constructors is strict mode code if the last argument is a String that when processed is a FunctionBody that begins with a Directive Prologue that contains a Use Strict Directive.
关于javascript - 不建议在 ES6 中使用 "use strict"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31685262/