Just don’t use it:
http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/
JavaScript’s
withstatement was intended to provide a shorthand for writing recurring accesses to objects. So instead of writingooo.eee.oo.ah_ah.ting.tang.walla.walla.bing = true; ooo.eee.oo.ah_ah.ting.tang.walla.walla.bang = true;You can write
with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) { bing = true; bang = true; }That looks a lot nicer. Except for one thing. There is no way that you can tell by looking at the code which
bingandbangwill get modifed. Willooo.eee.oo.ah_ah.ting.tang.walla.wallabe modified? Or will the global variablesbingandbangget clobbered? It is impossible to know for sure…If you can’t read a program and be confident that you know what it is going to do, you can’t have confidence that it is going to work correctly. For this reason, the
withstatement should be avoided…