<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: with Statement Considered Harmful</title>
	<atom:link href="http://www.yuiblog.com/blog/index.php/2006/04/11/with-statement-considered-harmful/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/</link>
	<description>The official blog of the YUI Project.</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:46:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: ECMAScript&#160;5, die nächste Version von JavaScript&#160;&#8211; Teil 1: Ein Überblick • Peter Kröner, Webdesigner &#38; Frontendentwickler</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-597940</link>
		<dc:creator>ECMAScript&#160;5, die nächste Version von JavaScript&#160;&#8211; Teil 1: Ein Überblick • Peter Kröner, Webdesigner &#38; Frontendentwickler</dc:creator>
		<pubDate>Tue, 05 Apr 2011 08:30:46 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-597940</guid>
		<description>[...] von Scripts können in einen Strict Mode versetzt werden, in dem einige defekte JS-Altlasten (z.B. with(){}) nicht mehr verwendet werden können und der an einigen Stellen die Regeln von JavaScript so [...]</description>
		<content:encoded><![CDATA[<p>[...] von Scripts können in einen Strict Mode versetzt werden, in dem einige defekte JS-Altlasten (z.B. with(){}) nicht mehr verwendet werden können und der an einigen Stellen die Regeln von JavaScript so [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: danomator</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-597642</link>
		<dc:creator>danomator</dc:creator>
		<pubDate>Fri, 04 Mar 2011 15:16:34 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-597642</guid>
		<description>This might be a solution to the problem if anyone really needs to use with():


var obj = {a : &#039;foo&#039;, b : &#039;bar&#039;}, b = &#039;brain&#039;;

// add _ prefix to object elements
function _(obj)
{
	for (var prop in obj)
		this[&#039;_&#039;+prop] = obj[prop];
}

// write obj.a and obj.b
with (obj)
{
	document.write(a);
	document.write(b);
}

document.write(&#039;&#039;);

// write obj.a and global b
with (new _(obj))
{
	document.write(_a);
	document.write(b);
}

// original object still remains
for (var prop in obj)
	document.write(&#039;&#039;+prop+&#039; = &#039;+obj[prop]);</description>
		<content:encoded><![CDATA[<p>This might be a solution to the problem if anyone really needs to use with():</p>
<p>var obj = {a : &#8216;foo&#8217;, b : &#8216;bar&#8217;}, b = &#8216;brain&#8217;;</p>
<p>// add _ prefix to object elements<br />
function _(obj)<br />
{<br />
	for (var prop in obj)<br />
		this['_'+prop] = obj[prop];<br />
}</p>
<p>// write obj.a and obj.b<br />
with (obj)<br />
{<br />
	document.write(a);<br />
	document.write(b);<br />
}</p>
<p>document.write(&#8221;);</p>
<p>// write obj.a and global b<br />
with (new _(obj))<br />
{<br />
	document.write(_a);<br />
	document.write(b);<br />
}</p>
<p>// original object still remains<br />
for (var prop in obj)<br />
	document.write(&#8221;+prop+&#8217; = &#8216;+obj[prop]);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Douglas Crockford</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-597551</link>
		<dc:creator>Douglas Crockford</dc:creator>
		<pubDate>Tue, 22 Feb 2011 19:59:17 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-597551</guid>
		<description>The point is not that -with- is useless. The point is that it is, unfortunately, dangerous. And that it is, fortunately, unnecessary. Features that are both dangerous and unnecessary should to be used at all.</description>
		<content:encoded><![CDATA[<p>The point is not that -with- is useless. The point is that it is, unfortunately, dangerous. And that it is, fortunately, unnecessary. Features that are both dangerous and unnecessary should to be used at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Why is the &#34;with&#34; statement in JavaScript often discouraged? - Quora</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-597498</link>
		<dc:creator>Why is the &#34;with&#34; statement in JavaScript often discouraged? - Quora</dc:creator>
		<pubDate>Thu, 17 Feb 2011 09:40:30 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-597498</guid>
		<description>[...] geek, loves Mac a... To add, this article and also it&#039;s comments highlight few points. http://www.yuiblog.com/blog/2006...  Another point to add, I think it also hurts performance because it adds one more level of scope [...]</description>
		<content:encoded><![CDATA[<p>[...] geek, loves Mac a&#8230; To add, this article and also it&#039;s comments highlight few points. <a href="http://www.yuiblog.com/blog/2006.." rel="nofollow">http://www.yuiblog.com/blog/2006..</a>.  Another point to add, I think it also hurts performance because it adds one more level of scope [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jameshooo</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-597339</link>
		<dc:creator>jameshooo</dc:creator>
		<pubDate>Wed, 26 Jan 2011 06:27:36 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-597339</guid>
		<description>(function(){
  with(this){  // &#039;this&#039; is one of scope chains
    bing = true;
    bang = true;
  }
}).apply(ooo.eee.oo.ah_ah.ting.tang.walla.walla);

If &#039;bing&#039; is member of walla, then walla.bing will be setted.
If &#039;bing&#039; is not member of walla, then bing will be global variant.</description>
		<content:encoded><![CDATA[<p>(function(){<br />
  with(this){  // &#8216;this&#8217; is one of scope chains<br />
    bing = true;<br />
    bang = true;<br />
  }<br />
}).apply(ooo.eee.oo.ah_ah.ting.tang.walla.walla);</p>
<p>If &#8216;bing&#8217; is member of walla, then walla.bing will be setted.<br />
If &#8216;bing&#8217; is not member of walla, then bing will be global variant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Improve page load times by compressing code; or, &#34;mnfy ur JS&#34; &#124; Scott Bush</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-596794</link>
		<dc:creator>Improve page load times by compressing code; or, &#34;mnfy ur JS&#34; &#124; Scott Bush</dc:creator>
		<pubDate>Tue, 28 Dec 2010 00:52:28 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-596794</guid>
		<description>[...] way only works if you avoid using the javascript function eval() and statement with, both of which are vilified for their blocking of javascript minifying, among other issues.) A real-world example of [...]</description>
		<content:encoded><![CDATA[<p>[...] way only works if you avoid using the javascript function eval() and statement with, both of which are vilified for their blocking of javascript minifying, among other issues.) A real-world example of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MooGoo</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-594291</link>
		<dc:creator>MooGoo</dc:creator>
		<pubDate>Tue, 14 Sep 2010 15:19:19 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-594291</guid>
		<description>&quot;You could also write that as

Math.cos(Math.asin(0.5))

which would be smaller, faster, and more legible.&quot;

Or you could write it as

with(Math) cos(asin(0.5));


Which is even smaller, much more legible, and importantly, far more similar to what real mathematical equations look like.

I also doubt very much that this is in any significant way slower than referencing &#039;Math&#039; multiple times.

It is probably not worth the trouble to use &#039;with&#039; for a mere 2 function calls, but if you are doing much more, it seems like a great way to make your code more legible. And in the case of &#039;with(Math)&#039; there is absolutely no ambiguity about what object sin/cos/floor/ceil/pow etc. come from.</description>
		<content:encoded><![CDATA[<p>&#8220;You could also write that as</p>
<p>Math.cos(Math.asin(0.5))</p>
<p>which would be smaller, faster, and more legible.&#8221;</p>
<p>Or you could write it as</p>
<p>with(Math) cos(asin(0.5));</p>
<p>Which is even smaller, much more legible, and importantly, far more similar to what real mathematical equations look like.</p>
<p>I also doubt very much that this is in any significant way slower than referencing &#8216;Math&#8217; multiple times.</p>
<p>It is probably not worth the trouble to use &#8216;with&#8217; for a mere 2 function calls, but if you are doing much more, it seems like a great way to make your code more legible. And in the case of &#8216;with(Math)&#8217; there is absolutely no ambiguity about what object sin/cos/floor/ceil/pow etc. come from.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mynamehere</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-594279</link>
		<dc:creator>mynamehere</dc:creator>
		<pubDate>Mon, 13 Sep 2010 22:33:53 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-594279</guid>
		<description>Okay, I think we can all agree that, when talking about the ooo.eee.oo.ah_ah.ting.tang.walla.walla object, it is NEVER a good idea--due to certain nebulous security issues inherent in the JavaScript engine--to set bing AND bang to true at the same time!</description>
		<content:encoded><![CDATA[<p>Okay, I think we can all agree that, when talking about the ooo.eee.oo.ah_ah.ting.tang.walla.walla object, it is NEVER a good idea&#8211;due to certain nebulous security issues inherent in the JavaScript engine&#8211;to set bing AND bang to true at the same time!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Sciberras</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-594190</link>
		<dc:creator>Christian Sciberras</dc:creator>
		<pubDate>Mon, 06 Sep 2010 10:13:32 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-594190</guid>
		<description>By the same reasoning...

&lt;code&gt;
var test=&#039;global&#039;;


function doTest(){
  var test=&#039;function&#039;;
  return test;
}

alert(doTest());
alert(test);

&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>By the same reasoning&#8230;</p>
<p><code><br />
var test='global';</p>
<p>function doTest(){<br />
  var test='function';<br />
  return test;<br />
}</p>
<p>alert(doTest());<br />
alert(test);</p>
<p></code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Ribeiro</title>
		<link>http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/comment-page-2/#comment-593375</link>
		<dc:creator>Daniel Ribeiro</dc:creator>
		<pubDate>Wed, 18 Aug 2010 02:03:44 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/#comment-593375</guid>
		<description>This is all very pretty, and nice to know, and should be accepted as norm of regular code. However, DSLs are very useful, are not normal code in most languages (method chaining technique is famous for breaking &lt;a href=&quot;http://en.wikipedia.org/wiki/Law_Of_Demeter&quot; rel=&quot;nofollow&quot;&gt;Law of Demeter&lt;/a&gt;), as Martin Fowler says on his &lt;a href=&quot;http://martinfowler.com/dslwip/MethodChaining.html&quot; rel=&quot;nofollow&quot;&gt;introduction&lt;/a&gt; to the topic: &lt;i&gt;As you can see methods defined for Method Chaining  violate basic rules for API design&lt;/i&gt;. A &lt;a href=&quot;http://github.com/alexyoung/javascript-dsl-examples/blob/master/with_dsl_new_function.js&quot; rel=&quot;nofollow&quot;&gt;DSL&lt;/a&gt; (with stripped commas for a bit less of noise) that is only possible with the &#039;with&#039; statement (or instance_eval in Ruby):


&lt;blockquote&gt;DSLRunner.run(function() {
  bake(function() {
    addIngredient(&#039;flour&#039;)
    addIngredient(&#039;yeast&#039;)
    addIngredient(&#039;water&#039;)

    print(&quot;Baking bread&quot;)
  });

  bake(function() {
    print(&quot;Baking a cake&quot;)
  });
&lt;/blockquote&gt;

Remember:
&lt;i&gt;Rebels learn the rules better than the rule-makers do. Rebels learn where the holes are, where the rules can be breached. Become an expert at the rules. Then break them with creativity and style.&lt;/i&gt;
-Kristine Kathryn Rusch
</description>
		<content:encoded><![CDATA[<p>This is all very pretty, and nice to know, and should be accepted as norm of regular code. However, DSLs are very useful, are not normal code in most languages (method chaining technique is famous for breaking <a href="http://en.wikipedia.org/wiki/Law_Of_Demeter" rel="nofollow">Law of Demeter</a>), as Martin Fowler says on his <a href="http://martinfowler.com/dslwip/MethodChaining.html" rel="nofollow">introduction</a> to the topic: <i>As you can see methods defined for Method Chaining  violate basic rules for API design</i>. A <a href="http://github.com/alexyoung/javascript-dsl-examples/blob/master/with_dsl_new_function.js" rel="nofollow">DSL</a> (with stripped commas for a bit less of noise) that is only possible with the &#8216;with&#8217; statement (or instance_eval in Ruby):</p>
<blockquote><p>DSLRunner.run(function() {<br />
  bake(function() {<br />
    addIngredient(&#8216;flour&#8217;)<br />
    addIngredient(&#8216;yeast&#8217;)<br />
    addIngredient(&#8216;water&#8217;)</p>
<p>    print(&#8220;Baking bread&#8221;)<br />
  });</p>
<p>  bake(function() {<br />
    print(&#8220;Baking a cake&#8221;)<br />
  });
</p></blockquote>
<p>Remember:<br />
<i>Rebels learn the rules better than the rule-makers do. Rebels learn where the holes are, where the rules can be breached. Become an expert at the rules. Then break them with creativity and style.</i><br />
-Kristine Kathryn Rusch</p>
]]></content:encoded>
	</item>
</channel>
</rss>

