JavaScript的with语句的未来 [英] Future of the with-statement in Javascript

查看:143
本文介绍了JavaScript的with语句的未来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道不建议使用 - 陈述 a>在Javascript中,并禁止在ECMAScript 5,但它允许一个在Javascript中创建一些不错的DSL。

I know that usage of the with-statement is not recommended in Javascript and is forbidden in ECMAScript 5, but it allows one to create some nice DSLs in Javascript.

例如 CoffeeKup 模板引擎和 Zappa 网络DSL。那些使用一些非常 weird 范围设定方法与 - 陈述,以实现对他们的DSLish感觉。

For example CoffeeKup-templating engine and the Zappa web DSL. Those uses some very weird scoping methods with the with-statement to achieve DSLish feeling to them.

-statement和这些类型的DSL有没有任何未来?

Is there any future with the with-statement and these kinds of DSLs?


Can this DSL-effect be achieved without the with-statement?

推荐答案

使用 code>在ECMAScript 5中为禁止是常见误解

with being "forbidden" in ECMAScript 5 is a common misconception.

只有在ECMAScript 5的严格模式(即选择启用)中,请注意 - 语句是一个语法错误。因此,您可以在完全的ECMAScript 5兼容实现中仍然使用,只要它们出现在非严格(或像Crockford调用它)。对于性能来说不是很好(因为与的关系经常会导致现代引擎中的各种优化),但它会奏效。

Only in strict mode of ECMAScript 5 — which is opt-in, mind you — with statement is a syntax error. So you can certainly still use with in fully ECMAScript 5 -compliant implementations, as long as they occur in non-strict (or sloppy, as Crockford calls it) code. It won't be pretty for performance (since mere presence of with often kills various optimizations in modern engines) but it will work.

ECMAScript的未来版本很可能基于严格模式行为,虽然也可能选择加入。所以符合严格模式肯定是一个好主意,当涉及到未来证明你的脚本。

Future versions of ECMAScript are very likely to be based on strict mode behavior, although will also likely be opt-in as well. So conforming to strict mode is certainly a good idea when it comes to future proofing your scripts.

这篇关于JavaScript的with语句的未来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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