Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
309 views
in Technique[技术] by (71.8m points)

javascript - 不建议在ES6中使用“严格使用”?(Not recommended to use “use strict” in ES6?)

I'm not familiar with ECMAScript 6 yet.

(我对ECMAScript 6还不熟悉。)

I've just cloned the React Starter Kit repo, which uses ES6 for application code.

(我刚刚克隆了React Starter Kit仓库,该仓库使用ES6作为应用程序代码。)

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.

(我很惊讶地看到linter被配置为禁止use strict指令,我认为在ES6之前的JavaScript中建议use strict该指令。)

So what's the point?

(那有什么意义呢?)

  ask by Midiparse translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

ES6 modules are always in strict mode.

(ES6模块始终处于严格模式。)

To quote the relevant part of the spec :

(引用规范的相关部分:)

10.2.1 Strict Mode Code(10.2.1严格模式代码)

An ECMAScript Script syntactic unit may be processed using either unrestricted or strict mode syntax and semantics.

(可以使用非限制或严格模式的语法和语义来处理ECMAScript脚本语法单元。)

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).

    (如果全局代码以包含使用严格指令的指令序言开头(请参见14.1.1),则它是严格模式代码。)

  • Module code is always strict mode code.

    (模块代码始终是严格模式代码。)

  • All parts of a ClassDeclaration or a ClassExpression are strict mode code.

    (ClassDeclaration或ClassExpression的所有部分都是严格模式代码。)

  • 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.

    (如果Eval代码以包含使用严格指令的指令序言开头,或者如果eval的调用是包含在严格模式代码中的直接eval(请参阅12.3.4.1),则它是严格模式代码。)

  • 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.

    (如果在严格模式代码中包含相关的FunctionDeclaration,FunctionExpression,GeneratorDeclaration,GeneratorExpression,MethodDefinition或ArrowFunction,或者如果产生该函数的[[ECMAScriptCode]]内部插槽值的代码以伪指令开头,则函数代码为严格模式代码。包含“使用严格”指令。)

  • 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.

    (如果最后一个参数是一个字符串,则该函数代码作为内置函数和生成器构造函数的参数提供的函数代码是严格模式代码,该字符串在处理时是一个以包含“使用严格指令”的指令序言开头的FunctionBody。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...