This article about Javascript Strict Mode might interest you: John Resig - ECMAScript 5 Strict Mode, JSON, and More
(这篇有关Javascript严格模式的文章可能会让您感兴趣: John Resig-ECMAScript 5严格模式,JSON等)
To quote some interesting parts:
(引用一些有趣的部分:)
Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context.
(严格模式是ECMAScript 5中的一项新功能,可让您将程序或功能置于“严格”的操作环境中。)
This strict context prevents certain actions from being taken and throws more exceptions. (这种严格的上下文会阻止采取某些措施,并引发更多异常。)
And:
(和:)
Strict mode helps out in a couple ways:
(严格模式可以通过以下两种方式提供帮助:)
Also note you can apply "strict mode" to the whole file... Or you can use it only for a specific function (still quoting from John Resig's article) :
(还要注意,您可以将“严格模式”应用于整个文件...或者您只能将其用于特定功能(仍引用John Resig的文章) :)
// Non-strict code... (function(){ "use strict"; // Define your library strictly... })(); // Non-strict code...
Which might be helpful if you have to mix old and new code ;-)
(如果您必须混合使用新旧代码,这可能会有所帮助;-))
So, I suppose it's a bit like the "use strict"
you can use in Perl (hence the name?) : it helps you make fewer errors, by detecting more things that could lead to breakages.
(因此,我想这有点像您可以在Perl中使用"use strict"
(因此得名?) :它通过检测更多可能导致损坏的内容来帮助您减少错误。)
Strict mode is now supported by all major browsers .
(所有主要浏览器现在都支持严格模式。)
Inside native ECMAScript modules (with import
and export
statements) and ES6 classes , strict mode is always enabled and cannot be disabled.
(在本机ECMAScript模块 (带有import
和export
语句)和ES6类中 ,严格模式始终处于启用状态,不能被禁用。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…