哪些 ECMAScript 6 特性意味着严格模式? [英] Which ECMAScript 6 features imply strict mode?
问题描述
在 ECMAScript 5(又名 JavaScript)中,我可以通过在函数(或文件,但不鼓励这样做)的顶部添加 "use strict"
来触发严格模式.
In ECMAScript 5 (aka JavaScript,) I can trigger strict mode by adding "use strict"
at the top of my function (or file, but this is discouraged.)
我知道在 ECMAScript 6 中,某些语法特性会打开严格模式,尤其是 class
和模块(不管你怎么做.)
I understand that in ECMAScript 6, certain syntax features will turn on strict mode, especially class
, and modules (however you do those.)
在 ECMAScript 6 世界中,触发严格模式的完整方法列表是什么?
推荐答案
规范 说:
- 模块代码始终是严格模式代码.
- ClassDeclaration 或 ClassExpression 的所有部分都是严格模式代码.
- …
- Module code is always strict mode code.
- All parts of a ClassDeclaration or a ClassExpression are strict mode code.
- …
剩下的只是ES5中已知的东西,基本上所有以"use strict";
指令.它也适用于新的 ES6 函数类型(箭头、生成器、方法语法).
The rest are just the known things from ES5, basically every global/eval/function code that begins with the "use strict";
directive. It does work within the new ES6 function kinds (arrow, generator, method syntax) as well.
这篇关于哪些 ECMAScript 6 特性意味着严格模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!