- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我找到了这篇文章-What does "use strict" do in JavaScript, and what is the reasoning behind it?
我在这里理解的是,我应该使用严格
始终。
但我想知道,如果这是真的,那么使用“严格模式”总是更好,那么它甚至不会存在,因为这将是默认行为。
所以我搜索了 ECMAScript 第六版定义,发现它是很多情况下的默认定义。
据official documentation about strict mode
An ECMAScript Script syntactic unit may be processed using either unrestricted or strict mode syntax and semantics. The 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.
ECMAScript code that is not strict mode code is called non-strict code.
那么,什么时候使用非严格代码是一个好的选择?
提前致谢。
最佳答案
So, when is a good choice to not use strict mode?
当您运行尚 future 得及更新的旧(或第三方)代码时。
严格模式更好。默认情况下它不会打开,因为它会破坏未考虑到它而编写的旧代码。
关于javascript - 什么时候不应该在 JavaScript 中使用 "strict mode"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44587711/
JavaScript 不关心字符串是双引号 "double" 还是单引号 'single'。 ECMAScript 5 严格模式的每个示例都通过双引号中的 "use strict" 启用。我可以执行以
这个问题在这里已经有了答案: What does "use strict" do in JavaScript, and what is the reasoning behind it? (30 个答
对于下面的代码片段 案例 1:严格模式 "use strict" let obj = { method: function(){ console.log(this); }, arr
function useStrict(){ "use strict"; } "use strict";
协议(protocol): http://opengraphprotocol.org/ 声明使用 带有 property 属性的标签. AFAIK,这不是有效的 XHTML 1.0 Strict 值。
我研究了一些库,它们似乎不包含文件或函数级别的 "use strict"; 行。因此,如果开发人员启用严格模式,那么我们如何知道库是否兼容?可能会有一些奇怪的功能或浏览器特定问题,这些问题在启用严格模
如果我们的 html 文件(导入外部 js 文件)已经有“use strict”,我们是否需要在外部 js 文件中加入“use strict”? 如果我们的外部 js 文件没有“use strict”
我相信这里的每个人都知道我们无法在不破坏 IE 兼容性的情况下为 XHTML 提供具有正确 MIME 类型 (application/xhtml+xml) 的页面,并且任何使用 text/html 提
我将这些定义放在一个文件中: x = 'a' : 'b' : 'c' : [] y = ['a', 'b', 'c'] (重要的是在文件中定义它们,而不是在 GHCi 中,因为在后一种情况下,事情变得
我想在 javascript 中使用 "use strict"; 模式,但在严格警告方面存在一些问题。我有一个“小部件”,例如: var Widget = function () { /* ... *
inline void addHeader(T value) { if(sizeof(T) > m_outputBufferStart) { std::clog <<
为什么 XHTML 1.0 Strict 显示的行高比 XHTML 1.0 Transitional 中相同值的行高显示得大? 因此,这将下推表格单元格中的内容(即 Firefox 中的 Hotmai
ECMAScript5中引入的严格模式,通过让JavaScript运行环境对一些开发过程中最常见和不易发现的错误做出和当前不同的处理,来让开发者拥有一个”更好”的JavaScript语言。很长一段时
I. Strict Mode阐述 根据 mysql5.0以上版本 strict mode (STRICT_TRANS_TABLES) 的限制: 1).不支持对not null字段插入null值
本文分享自华为云社区《JS/TS里的"use strict"严格模式是什么?》,作者: gentle_zhou。 在日常JS/TS项目开发过程中,经常会在文件开头看到"use strcit"字样,这里
在本教程中,您将借助示例了解 JavaScript 的“严格模式”语法。 在 JavaScript 中,‘use strict’; 声明代码应该在“严格模式”下执行。这使得编写良好且安全的 J
我在学习 JS 时遇到了“use strict”。然后,这里Should I 'use strict' for every single javascript function I write? @B
嗨我最近一直在使用下面的命令 Ffmpeg -i song.mp3 -loop 1 -i image.jpg -filter_complex \ "[0:a]showfreqs=mode=line:a
如果 use strict;,我有几行代码可以工作被注释掉了。但是,我不想仅仅因为一小部分而在整个脚本中禁用它。 我需要重新编码,或者以某种方式禁用 use strict;暂时,然后重新启用它。第一个
在 Angular 10 中,您可以使用 ng new --strict 创建一个新项目。 Enabling this flag initializes your new project with a
我是一名优秀的程序员,十分优秀!