不推荐使用“use strict"在 ES6 中? [英] Not recommended to use "use strict" in ES6?

查看:27
本文介绍了不推荐使用“use strict"在 ES6 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还不熟悉 ECMAScript 6.我刚刚克隆了 React Starter Kit 存储库,它使用 ES6 作为应用程序代码.我很惊讶地看到 linter 被配置禁止use strict 指令的出现,我认为这是在 ES6 之前的 JavaScript 中推荐的.那么重点是什么?

I'm not familiar with ECMAScript 6 yet. I've just cloned the React Starter Kit repo, which uses ES6 for application code. I was surprised to see that the linter is configured to forbid occurences of the use strict directive, which I thought was recommended in pre-ES6 JavaScript. So what's the point?

推荐答案

ES6 模块始终处于严格模式.引用规范的相关部分:

ES6 modules are always in strict mode. To quote the relevant part of the spec:

ECMAScript Script 语法单元可以使用不受限制或严格模式的语法和语义进行处理.在以下情况下,代码被解释为严格模式代码:

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:

  • 如果全局代码以包含使用严格指令的指令序言开头(参见 14.1.1),则它是严格模式代码.
  • 模块代码始终是严格模式代码.
  • ClassDeclaration 或 ClassExpression 的所有部分都是严格模式代码.
  • 如果 Eval 代码以包含使用严格指令的指令序言开头,或者如果对 eval 的调用是包含在严格模式代码中的直接 eval(参见 12.3.4.1),则它是严格模式代码.
  • 如果相关的 FunctionDeclaration、FunctionExpression、GeneratorDeclaration、GeneratorExpression、MethodDefinition 或 ArrowFunction 包含在严格模式代码中,或者产生函数 [[ECMAScriptCode]] 内部槽值的代码以包含使用严格指令的指令序言.
  • 作为参数提供给内置函数和生成器构造函数的函数代码是严格模式代码,如果最后一个参数是一个字符串,当处理时它是一个以包含使用严格指令的指令序言开头的函数体.

这篇关于不推荐使用“use strict"在 ES6 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆