我还不熟悉ECMAScript 6。我刚刚克隆了React Starter Kit repo,它使用ES6作为应用程序代码。我很惊讶地看到linter被配置为禁止use strict指令的出现,我认为这是在es6之前的JavaScript中推荐的。那么这有什么意义呢?
ES6模块总是处于严格模式。引用规范的相关部分:
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.
推荐文章
- 如何唯一地识别访问我网站的计算机?
- 在node.js中使用async / await文件系统
- 导出ES6模块中的多个类
- 不建议在ES6中使用“use strict”?
- 将字符串转换为模板字符串
- 从常规ES6类方法调用静态方法
- 什么是虚拟DOM?
- 删除数组中所有对象的属性
- 资源解释为文档,但使用MIME类型application/zip传输
- 如何用jquery或javascript排序对象数组
- 在没有jQuery的情况下,防止悬停父div的子元素时onmouseout
- 如何知道一个字符串开始/结束在jQuery特定的字符串?
- 用JavaScript检测文本中的url
- 将对象序列化为JSON
- Gzip的JavaScript实现