<?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: Anti-patterns in the making</title>
	<atom:link href="http://james.padolsey.com/javascript/anti-patterns-in-the-making/feed/" rel="self" type="application/rss+xml" />
	<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:03:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: James</title>
		<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/comment-page-1/#comment-25419</link>
		<dc:creator>James</dc:creator>
		<pubDate>Sat, 05 Dec 2009 18:08:40 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1258#comment-25419</guid>
		<description>@Pete,

&lt;blockquote&gt;&lt;p&gt;&quot;The self invoking function pattern does get misused by people who don’t really understand what it does&quot;&lt;/p&gt;&lt;/blockquote&gt;

I know &quot;what it does&quot;, but I&#039;m the first to say that I misuse it quite a lot.

Also, it&#039;s quite difficult to know what classes as &quot;misuse&quot;. Say, for example, I have to prepare a value - this only needs to happen once - but the preparation of this value is complex, and would certainly complicate the surrounding code if left un-contained. In such a situation I would use the mentioned construct to provide such containment.

@Nick, what sucks is that the &lt;code&gt;with&lt;/code&gt; statement has been deprecated in ES5. It&#039;s a classic case of punishing the whole class because a couple kids mess around. Sure, the &lt;code&gt;with&lt;/code&gt; statement can be misused, but it can also be used to great effect.</description>
		<content:encoded><![CDATA[<p>@Pete,</p>
<blockquote><p>&#8220;The self invoking function pattern does get misused by people who don’t really understand what it does&#8221;</p>
</blockquote>
<p>I know &#8220;what it does&#8221;, but I&#8217;m the first to say that I misuse it quite a lot.</p>
<p>Also, it&#8217;s quite difficult to know what classes as &#8220;misuse&#8221;. Say, for example, I have to prepare a value &#8211; this only needs to happen once &#8211; but the preparation of this value is complex, and would certainly complicate the surrounding code if left un-contained. In such a situation I would use the mentioned construct to provide such containment.</p>
<p>@Nick, what sucks is that the <code>with</code> statement has been deprecated in ES5. It&#8217;s a classic case of punishing the whole class because a couple kids mess around. Sure, the <code>with</code> statement can be misused, but it can also be used to great effect.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Fitzgerald</title>
		<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/comment-page-1/#comment-25407</link>
		<dc:creator>Nick Fitzgerald</dc:creator>
		<pubDate>Fri, 04 Dec 2009 17:36:51 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1258#comment-25407</guid>
		<description>@Pete,

I believe that Andrea&#039;s point was not that self invoking functions are inherently &quot;bad&quot;, but that they have their use cases. Many people (myself included) have used or do use self invoking functions to avoid polluting whichever namespace they are inside (which is great when in the global scope, as you and many others will point out). Often times, you can achieve the same thing with less code, and without creating an unnecessary closure by using the with statement.

If I were to boil it down to the essence (apologies to Andrea if I butcher anything): Every trick can be used or misused (self invoking functions and with), but that doesn&#039;t mean we should blindly refuse to use one or the other, but that we should think about which will be best for the current situation.</description>
		<content:encoded><![CDATA[<p>@Pete,</p>
<p>I believe that Andrea&#8217;s point was not that self invoking functions are inherently &#8220;bad&#8221;, but that they have their use cases. Many people (myself included) have used or do use self invoking functions to avoid polluting whichever namespace they are inside (which is great when in the global scope, as you and many others will point out). Often times, you can achieve the same thing with less code, and without creating an unnecessary closure by using the with statement.</p>
<p>If I were to boil it down to the essence (apologies to Andrea if I butcher anything): Every trick can be used or misused (self invoking functions and with), but that doesn&#8217;t mean we should blindly refuse to use one or the other, but that we should think about which will be best for the current situation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete</title>
		<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/comment-page-1/#comment-25401</link>
		<dc:creator>Pete</dc:creator>
		<pubDate>Fri, 04 Dec 2009 09:35:31 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1258#comment-25401</guid>
		<description>Hmmm, I think the string split example is easier to type and maintain so I would choose it for those reasons.

The self invoking function pattern does get misused by people who don&#039;t really understand what it does, but it is popular for a good reason; @nick the example may be out of context but if it was standalone then it would prevent a global variable, which is a real benefit. 

Having looked at the Andrea Giammarchi example use of &#039;with&#039; I notice it has a very dubious reliance on the implied end-of-line semi-colon, I&#039;d run a mile from that :)</description>
		<content:encoded><![CDATA[<p>Hmmm, I think the string split example is easier to type and maintain so I would choose it for those reasons.</p>
<p>The self invoking function pattern does get misused by people who don&#8217;t really understand what it does, but it is popular for a good reason; @nick the example may be out of context but if it was standalone then it would prevent a global variable, which is a real benefit. </p>
<p>Having looked at the Andrea Giammarchi example use of &#8216;with&#8217; I notice it has a very dubious reliance on the implied end-of-line semi-colon, I&#8217;d run a mile from that <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nick Fitzgerald</title>
		<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/comment-page-1/#comment-25386</link>
		<dc:creator>Nick Fitzgerald</dc:creator>
		<pubDate>Fri, 04 Dec 2009 01:37:33 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1258#comment-25386</guid>
		<description>Andrea Giammarchi was just ranting about how much people avoid the with statement but do things like what you just pointed out:

&lt;pre lang=&quot;javascript&quot;&gt;
// avoid global scope pollution
(function(e){
  e.insertBefore(
    document.createElement(&quot;script&quot;),
    e.firstChild
  ).text = &quot;alert(1)&quot;
  ;
   // feeling cool and clever
   // just to avoid &quot;var&quot;
})(document.documentElement);
&lt;/pre&gt;

http://webreflection.blogspot.com/2009/12/with-worlds-most-misunderstood.html

I have to admit that I am guilty of doing exactly this. I think JS just needs a &quot;let&quot; expression similar to Lisp&#039;s (very different from the JS 1.8 &quot;let&quot; statement).

I often do the self invoking function thing on returns when I can&#039;t squeeze a &quot;return foo ? bar : baz;&quot; in there instead. I think in those cases it is acceptable (though I have definitely  misused self invoking functions plenty).</description>
		<content:encoded><![CDATA[<p>Andrea Giammarchi was just ranting about how much people avoid the with statement but do things like what you just pointed out:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span class="co1">// avoid global scope pollution</span>
<span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span><span class="br0">&#123;</span>
  e.<span class="me1">insertBefore</span><span class="br0">&#40;</span>
    document.<span class="me1">createElement</span><span class="br0">&#40;</span><span class="st0">&quot;script&quot;</span><span class="br0">&#41;</span><span class="sy0">,</span>
    e.<span class="me1">firstChild</span>
  <span class="br0">&#41;</span>.<span class="me1">text</span> <span class="sy0">=</span> <span class="st0">&quot;alert(1)&quot;</span>
  <span class="sy0">;</span>
   <span class="co1">// feeling cool and clever</span>
   <span class="co1">// just to avoid &quot;var&quot;</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#40;</span>document.<span class="me1">documentElement</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div>

<p><a href="http://webreflection.blogspot.com/2009/12/with-worlds-most-misunderstood.html">http://webreflection.blogspot.com/2009/12/with-worlds-most-misunderstood.html</a></p>
<p>I have to admit that I am guilty of doing exactly this. I think JS just needs a &#8220;let&#8221; expression similar to Lisp&#8217;s (very different from the JS 1.8 &#8220;let&#8221; statement).</p>
<p>I often do the self invoking function thing on returns when I can&#8217;t squeeze a &#8220;return foo ? bar : baz;&#8221; in there instead. I think in those cases it is acceptable (though I have definitely  misused self invoking functions plenty).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Roelofs</title>
		<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/comment-page-1/#comment-25385</link>
		<dc:creator>Roger Roelofs</dc:creator>
		<pubDate>Fri, 04 Dec 2009 00:18:36 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1258#comment-25385</guid>
		<description>Thanks for the article.  I have too lazy to type out an array on occasion, but I now have a macro that will turn &quot;this, that, the other&quot; into [&quot;this&quot;, &quot;that&quot;, &quot;the other&quot;].  In some ways, being lazy is an art form. :-)</description>
		<content:encoded><![CDATA[<p>Thanks for the article.  I have too lazy to type out an array on occasion, but I now have a macro that will turn &#8220;this, that, the other&#8221; into ["this", "that", "the other"].  In some ways, being lazy is an art form. <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark McDonnell</title>
		<link>http://james.padolsey.com/javascript/anti-patterns-in-the-making/comment-page-1/#comment-25381</link>
		<dc:creator>Mark McDonnell</dc:creator>
		<pubDate>Thu, 03 Dec 2009 23:49:01 +0000</pubDate>
		<guid isPermaLink="false">http://james.padolsey.com/?p=1258#comment-25381</guid>
		<description>I do believe self-executing functions have a place and a purpose and they carry out that purpose well. But I agree that their once esoteric appearance has now become the &quot;in thing&quot; to do, even when there is no actual point in using it.

I&#039;ll be honest though, I don&#039;t think I&#039;ve EVER been so lazy I couldn&#039;t type out a proper Array! :)</description>
		<content:encoded><![CDATA[<p>I do believe self-executing functions have a place and a purpose and they carry out that purpose well. But I agree that their once esoteric appearance has now become the &#8220;in thing&#8221; to do, even when there is no actual point in using it.</p>
<p>I&#8217;ll be honest though, I don&#8217;t think I&#8217;ve EVER been so lazy I couldn&#8217;t type out a proper Array! <img src='http://james.padolsey.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

