哪个ECMAScript 6功能意味着严格的模式? [英] Which ECMAScript 6 features imply strict mode?

查看:155
本文介绍了哪个ECMAScript 6功能意味着严格的模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在ECMAScript 5(也称为JavaScript)中,我可以通过在我的函数(或文件)的顶部添加use strict来触发严格模式,但这是不鼓励的。 )



我明白,在ECMAScript 6中,某些语法功能将会打开严格模式,特别是 class 和模块(但是你这样做)。



在ECMAScript 6世界中,触发严格模式的完整方法是什么?

解决方案

规格说:



  • 模块代码是总是严格的模式代码。

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

  • ...


其余的只是ES5中已知的东西,基本上每个全局/ eval /函数代码以 使用严格; 指令。它在新的ES6功能类型(箭头,生成器,方法语法)中也起作用。


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

I understand that in ECMAScript 6, certain syntax features will turn on strict mode, especially class, and modules (however you do those.)

In the ECMAScript 6 world, what is the complete list of ways to trigger strict mode?

解决方案

The spec says:

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

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屋!

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