本文介绍了&QUOT与......; javascript中的关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现在javascript中,可以执行以下操作:

I recently discovered that in javascript, one can do something like the following:

with document{
    write('foo');
    body.scrollTop = x;
}

这方面的缺点是需要检查每个变量以查看是否它属于文档对象,会产生很大的开销。

The down side of this is that each variable needs to be checked to see if it belongs to the document object, creating a significant overhead.

或者,可以这样做:

var d = document;
d.write('foo');
d.body.scrollTop = x;

是否存在使用'with'关键字的合理情况?

Are there any situations where the use of the 'with' keyword is justified?

推荐答案

以下是一些支持with关键字的博文。但请阅读azazul发布的YUI博客文章!

Here are some blog posts in support of the with keyword. But please read the YUI blog entry that azazul posted as well!


这篇关于&QUOT与......; javascript中的关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 02:22
查看更多