“严格使用”在JavaScript中有什么作用,其背后的原因是什么?

别来无恙 提交于 2020-08-13 09:54:41

问题:

Recently, I ran some of my JavaScript code through Crockford's JSLint , and it gave the following error: 最近,我通过Crockford的JSLint运行了一些JavaScript代码,并给出了以下错误:

Problem at line 1 character 1: Missing "use strict" statement. 第1行第1个字符处的问题:缺少“使用严格”语句。

Doing some searching, I realized that some people add "use strict"; 进行搜索后,我发现有些人添加了"use strict"; into their JavaScript code. 纳入他们的JavaScript代码。 Once I added the statement, the error stopped appearing. 添加语句后,错误停止出现。 Unfortunately, Google did not reveal much of the history behind this string statement. 不幸的是,谷歌没有透露此字符串语句背后的许多历史。 Certainly it must have something to do with how the JavaScript is interpreted by the browser, but I have no idea what the effect would be. 当然,它一定与浏览器如何解释JavaScript有关,但是我不知道会有什么影响。

So what is "use strict"; 那么什么是"use strict"; all about, what does it imply, and is it still relevant? 所有的一切,这意味着什么,并且仍然有意义?

Do any of the current browsers respond to the "use strict"; 当前的浏览器是否响应"use strict"; string or is it for future use? 字符串还是将来使用?


解决方案:

参考一: https://stackoom.com/question/5bVz/严格使用-在JavaScript中有什么作用-其背后的原因是什么
参考二: https://oldbug.net/q/5bVz/What-does-use-strict-do-in-JavaScript-and-what-is-the-reasoning-behind-it
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!