admin管理员组

文章数量:1134568

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?

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?

Share Improve this question edited Jan 7, 2017 at 11:25 Midiparse asked Jul 28, 2015 at 19:18 MidiparseMidiparse 4,7817 gold badges31 silver badges52 bronze badges 3
  • 22 ES6 modules and classes are strict by default. – Ry- Commented Jul 28, 2015 at 19:22
  • 2 related: Which ECMAScript 6 features imply strict mode? – Bergi Commented Jul 28, 2015 at 19:59
  • I think there's something very misleading about ES6 claim of being strict by default. They simply aren't and many things that would be otherwise caught by 'use strict' are silently ignored. This requires some more clarification. – Pawel Commented Apr 6, 2022 at 15:33
Add a comment  | 

1 Answer 1

Reset to default 277

ES6 modules are always in strict mode. To quote the relevant part of 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.

本文标签: javascriptNot recommended to use quotuse strictquot in ES6Stack Overflow