<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://www.peerbox.com:8668/rdf'>
    <s:Snip rdf:about='http://www.peerbox.com:8668/rdf#start/2008-05-06/1'
         s:name='start/2008-05-06/1'
         s:cUser='kgr'
         s:oUser='kgr'
         s:mUser='kgr'>
        <s:content>1 Javascript &apos;with&apos; Statement *NOT* Considered Harmful {anchor:Javascript &apos;with&apos; Statement *NOT* Considered Harmful}&#xA;JavaScript guru Douglas Crockford {link:considers the ‘with’ statement harmful|http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/}.  &#xD;&#xA;&#xD;&#xA;His reasoning is that if you do something like this:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) {&#xD;&#xA;    bing = true;&#xD;&#xA;    bang = true;&#xD;&#xA;}&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Then “there is no way that you can tell by looking at the code which bing and bang will get modified”.&#xD;&#xA;&#xD;&#xA;He instead suggests doing something like this:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;var o = ooo.eee.oo.ah_ah.ting.tang.walla.walla;&#xD;&#xA;o.bing = true;&#xD;&#xA;o.bang = true;&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;But this doesn’t limit the scope of the ‘o’ variable and doesn’t have a satisfying block-structure (well, if that’s the sort of thing that brings you satisfaction).&#xD;&#xA;&#xD;&#xA;You might think that you could do something like this:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;{&#xD;&#xA;   var o = ooo.eee.oo.ah_ah.ting.tang.walla.walla;&#xD;&#xA;&#xD;&#xA;   o.bing = true;&#xD;&#xA;   o.bang = true;&#xD;&#xA;}&#xD;&#xA;// ‘o’ is still defined here&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;, to limit the scope and introduce a block-structure. But in the Firefox JS implementation at least, this doesn’t actually do what you would expect.  The ‘o’ variable is still defined after the end of the block.&#xD;&#xA;&#xD;&#xA;So here’s my solution:&#xD;&#xA;{code}&#xD;&#xA;with ({o:ooo.eee.oo.ah_ah.ting.tang.walla.walla}) {&#xD;&#xA;    o.bing = true;&#xD;&#xA;    o.bang = true;&#xD;&#xA;}&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Or if you’re feeling a little more Smalltalk-ish:&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;with ({self:ooo.eee.oo.ah_ah.ting.tang.walla.walla}) {&#xD;&#xA;    self.bing = true;&#xD;&#xA;    self.bang = true;&#xD;&#xA;}&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;Notice that rather than using the object directly, I&apos;ve put it into a map so that I can give it an explicit name.&#xD;&#xA;&#xD;&#xA;You can also use the same trick to define multiple variables; essentially using ‘with’ like you would use Lisp or Scheme’s ‘let’ statement.&#xD;&#xA;&#xD;&#xA;{code}&#xD;&#xA;with ({&#xD;&#xA;   walla : ooo.eee.oo.ah_ah.ting.tang.walla.walla,&#xD;&#xA;   wanka : ooo.eee.oo.ah_ah.ting.tank.walla.wanka&#xD;&#xA;     })&#xD;&#xA;{&#xD;&#xA;    walla.bing = true;&#xD;&#xA;    wanka.bang = true;&#xD;&#xA;}&#xD;&#xA;{code}&#xD;&#xA;&#xD;&#xA;You’ve gotta love JS’s Object/Map duality.&#xD;&#xA;&#xD;&#xA;</s:content>
        <s:mTime>2008-05-06 13:34:13.377</s:mTime>
        <s:cTime>2008-05-06 13:34:13.377</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>
