javascript - 不建议在 ES6 中使用 "use strict"?

标签 javascript ecmascript-6 strict es6-modules

我还不熟悉 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/

相关文章:

javascript - 在 Javascript 中制作函数的真实副本

c++ - 有没有人考虑过更多 "strict"风格的 C++,其中默认/需要初始化变量?

javascript - parent 高度80%的 child (高度不详)

javascript - 使用javascript隐藏和显示菜单ID

javascript/jquery 设置 var 没有发生

javascript - 您如何同时映射生成器结果?

javascript - 在javascript中计算字符串中的元音

javascript - 运行 Node 4.4.7 时收到严格模式警告

perl - 如何跳出 Perl 中的循环?

javascript - PHP 查询整个表格,同时有一个搜索框,无需提交表单即可搜索