哪些 (javascript) 环境支持 ECMAscript 5 严格模式? (又名“严格使用”)

发布于 2024-08-04 16:00:49 字数 518 浏览 4 评论 0原文

ECMAScript 5 已处于最终草案中,因为我写这个;这是由于包含一个严格模式,它将阻止您分配给全局对象、使用 eval 和其他限制。 (John Resig 的文章 是一个很好的介绍。)

这种神奇的理智保存模式是通过在文件(或函数)顶部包含字符串“use strict”来触发的。但是,在较旧的环境中,“use strict”是无操作的。如果您添加“use strict”并且不在严格的环境中对其进行测试,则可能会留下一颗由非真正严格的代码组成的定时炸弹,当它真正遇到严格的环境时,这些代码就会崩溃。

哪些环境真正尊重“use strict”?

ECMAScript 5 is in its final draft as I write this; It is due to include a strict mode which will prevent you from assigning to the global object, using eval, and other restrictions. (John Resig's Article is a good introduction.)

This magical sanity-saving mode is triggered by including the string "use strict" at the top of your file (or function.) However, in older environments, "use strict" is a no-op. If you add "use strict" and don't test it in a strict environment, you could be leaving a time-bomb of not-really-strict code that will break when it really hits a strict environment.

Which environments actually respect "use strict"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素染倾城色 2024-08-11 16:00:49

更新

请参阅我的兼容性表

原始回复

目前还没有。

Raphael Speyer 今年夏天致力于 Rhino 的 Mozilla 实现,据我所知,他们的实现已经接近完成。

我知道(基于 ES 讨论列表中的信息)微软计划将一些 ES5 功能包含到即将推出的 IE 版本中,并且他们现在很可能正在致力于严格模式实现(正如您可能知道的那样,IE8 已经包含了一些ES5 功能,例如 Object.defineProperty)。

还有 Google 的 Caja 项目,它在某些变体中模拟了严格模式的行为 (瓦利加、卡吉塔等)。

Crockford 最近还将此选项添加到 JSLint 中,但我不确定它是否真的会触发任何额外的操作验证(根据 ES5 严格规则)。

Update:

See my compatibility table.

Original response:

None as of now.

Raphael Speyer was working on Mozilla implementation for Rhino during this summer, and afaik, their implementation is pretty close to completion.

I know (based on info from ES-discuss list) that Microsoft is planning to include some of ES5 features into upcoming versions of IE and they might very well be working on strict mode implementation right now (as you probably know, IE8 already includes some of ES5 features, like Object.defineProperty).

There's also Google's Caja project which somewhat emulates behavior of strict mode in some of its variations (Valija, Cajita, etc).

Crockford also recently added this option to JSLint, but I'm not sure if it actually triggers any additional validations (as per ES5-strict rules).

黄昏下泛黄的笔记 2024-08-11 16:00:49

如今,Firefox 4 正式发布,成为“第一个支持 ES5 严格模式的浏览器”的获奖者。现在就可以开始使用了,只要在 Firefox 4 中测试即可。Safari


5.1+ 和 Chrome 13+ 也支持严格模式。


第一个位于:Besen。在德尔福中实现。我认为它是独立的,但我不确定。但它确实支持严格模式。

通过此兼容性表找到。


Jurassic 声称支持 ES5 严格模式。

Now that it's actually released, Firefox 4 is the winner of "first browser to support ES5 Strict Mode." Now you can start using it, as long as you test in Firefox 4.


Safari 5.1+ and Chrome 13+ Also support strict mode.


The first One is in: Besen. Implemented in Delphi. I think it's stand-alone, but I'm not sure. But it does support strict mode.

Found via this compatibility table.


Jurassic claims to support ES5 Strict Mode.

成熟稳重的好男人 2024-08-11 16:00:49

ECMAscript 5 严格模式要求主要浏览器(或更高版本)使用以下版本:

Chrome 13.0
Safari 5.1
火狐4.0
Internet Explorer 10.0
Opera 11.6

不,IE9 没有严格支持,它是 10 或更高版本的新增内容。

ECMAscript 5 strict mode requires these versions for major browsers (or higher):

Chrome 13.0
Safari 5.1
Firefox 4.0
Internet Explorer 10.0
Opera 11.6

No, IE9 does not have strict support, it's new to version 10 or later.

银河中√捞星星 2024-08-11 16:00:49

Opera 11.60 已经完全支持 ECMAScript 5.1 及其严格模式变体。请参阅@kangax 兼容性表。

Opera 11.60 already fully supports ECMAScript 5.1 and it's strict mode variation. See @kangax compatibility table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文