开发者

change JavaScript scope

Is there any posibility to exchange the special global window scope by a custom one? I just thought with is meant to, but it only stacks another "lookup" scope. Eg.

test={};
with(test){
    a=1;
}

does not create the property test.a but window.a.

So the window object has a JS-specific specia开发者_如何转开发l quality I cannot recreate with own code?


If the property exists on the object given to with then it will be modified, but it will never be created. This is a major "gotcha" with using with and the primary reason it should be avoided.


With with only if the object passed in has that property, will it be modified. It will not be created.

http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜