开发者

change JavaScript scope

开发者 https://www.devze.com 2023-02-28 14:02 出处:网络
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.

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

精彩评论

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

关注公众号