<?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/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
	>
<channel>
	<title>Comments on: Dirty looping in JavaScript</title>
	<atom:link href="http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/</link>
	<description>geek, punk, pussy …</description>
	<lastBuildDate>Sun, 05 May 2013 13:21:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
	<item>
		<title>By: Jose</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-34892</link>
		<dc:creator>Jose</dc:creator>
		<pubDate>Fri, 30 Nov 2012 03:26:29 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-34892</guid>
		<description>Good one!  Hoisting is a new concept to me, you helped clarify it.  This page is good too:

http://www.programmerinterview.com/index.php/javascript/javascript-hoisting/</description>
		<content:encoded><![CDATA[<p>Good one!  Hoisting is a new concept to me, you helped clarify it.  This page is good too:</p>
<p><a href="http://www.programmerinterview.com/index.php/javascript/javascript-hoisting/" rel="nofollow">http://www.programmerinterview.com/index.php/javascript/javascript-hoisting/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan Krechetov</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-116</link>
		<dc:creator>Ivan Krechetov</dc:creator>
		<pubDate>Tue, 17 Aug 2010 13:54:18 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-116</guid>
		<description>Nice tip, thanks! I also enjoyed the previous posts.

I guess, another fun thing to do is passing parameters in this nested loop&#039;s function:

[cc lang=&quot;javascript&quot;]
…
(function(j){
    …
})(i);
…
[/cc]

Thus, the enclosing loop&#039;s i becomes a j in the nested loop.</description>
		<content:encoded><![CDATA[<p>Nice tip, thanks! I also enjoyed the previous posts.</p>
<p>I guess, another fun thing to do is passing parameters in this nested loop&#8217;s function:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">…<br />
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; …<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
…</div></div>
<p>Thus, the enclosing loop&#8217;s i becomes a j in the nested loop.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre Spring</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-23</link>
		<dc:creator>Pierre Spring</dc:creator>
		<pubDate>Thu, 27 May 2010 12:17:35 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-23</guid>
		<description>&lt;strong&gt;@BOobby&lt;/strong&gt;: the problem with [cci]let[/cci] is that the scope of a variable declared inside a let statement using var is still the same as if it had been declared outside the let statement - such variables still have function scoping. 

In the above example, [cci]var row;[/cci] would still be in the scope of the whole function.

And of course,  [cci]let[/cci] only runs in FF &gt;= 3.0 ...</description>
		<content:encoded><![CDATA[<p><strong>@BOobby</strong>: the problem with <code class="codecolorer text default"><span class="text">let</span></code> is that the scope of a variable declared inside a let statement using var is still the same as if it had been declared outside the let statement &#8211; such variables still have function scoping. </p>
<p>In the above example, <code class="codecolorer text default"><span class="text">var row;</span></code> would still be in the scope of the whole function.</p>
<p>And of course,  <code class="codecolorer text default"><span class="text">let</span></code> only runs in FF >= 3.0 &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: BObby</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-22</link>
		<dc:creator>BObby</dc:creator>
		<pubDate>Thu, 27 May 2010 10:28:25 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-22</guid>
		<description>Or you could use the [cci lang=&quot;javascript&quot;]let[/cci] keyword in JavaScript 1.7+, but of course there are problems with this too.</description>
		<content:encoded><![CDATA[<p>Or you could use the <code class="codecolorer javascript default"><span class="javascript">let</span></code> keyword in JavaScript 1.7+, but of course there are problems with this too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre Spring</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-21</link>
		<dc:creator>Pierre Spring</dc:creator>
		<pubDate>Thu, 27 May 2010 06:42:39 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-21</guid>
		<description>&lt;strong&gt;Freeman:&lt;/strong&gt; The point I am trying to make is not to get the enclosing scope of a loop dirty. [cci]i[/cci] and [cci]row[/cci] declaration both get hoisted to the top if you don&#039;t wrap the loop in a function. And this can have unexpected results.

The [cci]assure_positive()[/cci] is for educational purpose and therefor it is kept very simple.</description>
		<content:encoded><![CDATA[<p><strong>Freeman:</strong> The point I am trying to make is not to get the enclosing scope of a loop dirty. <code class="codecolorer text default"><span class="text">i</span></code> and <code class="codecolorer text default"><span class="text">row</span></code> declaration both get hoisted to the top if you don&#8217;t wrap the loop in a function. And this can have unexpected results.</p>
<p>The <code class="codecolorer text default"><span class="text">assure_positive()</span></code> is for educational purpose and therefor it is kept very simple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A Freeman</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-20</link>
		<dc:creator>A Freeman</dc:creator>
		<pubDate>Thu, 27 May 2010 00:21:41 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-20</guid>
		<description>Why would you reuse the outer loop index for the inner loop, in the first place? Am I missing something here?

[cc lang=&quot;javascript&quot;]for (i=0;i&lt;matrix.length;i++) {
    var row=matrix[i];
    for (j=0;j&lt;row.length;j++) {
        // stuff happens here
    }
}[/cc]</description>
		<content:encoded><![CDATA[<p>Why would you reuse the outer loop index for the inner loop, in the first place? Am I missing something here?</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>matrix.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> row<span style="color: #339933;">=</span>matrix<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>j<span style="color: #339933;">&lt;</span>row.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// stuff happens here</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre Spring</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-19</link>
		<dc:creator>Pierre Spring</dc:creator>
		<pubDate>Tue, 25 May 2010 08:07:09 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-19</guid>
		<description>&lt;strong&gt;@jordi:&lt;/strong&gt; Where you put the closing parenthesis does not matter really, it is a question of convention. Crockford demands that you close it the way it&#039;s done in my examples, arguing that the way you do it makes no sense (c.f. &lt;u&gt;&lt;a href=&quot;http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-3&quot; rel=&quot;nofollow&quot;&gt;video 3&lt;/a&gt;&lt;/u&gt; at &lt;strong&gt;29&#039;28&#039;&#039;&lt;/strong&gt;)

To me both make perfect sense, yet &lt;strong&gt;I choose to adhere to the standards proposed by Crockford&lt;/strong&gt;.

The only important thing is to have the &lt;strong&gt;opening parenthesis&lt;/strong&gt;, in order to not to have a &lt;strong&gt;function expression&lt;/strong&gt; rather than a &lt;strong&gt;function statement&lt;/strong&gt;. The statement would not be callable.</description>
		<content:encoded><![CDATA[<p><strong>@jordi:</strong> Where you put the closing parenthesis does not matter really, it is a question of convention. Crockford demands that you close it the way it&#8217;s done in my examples, arguing that the way you do it makes no sense (c.f. <u><a href="http://developer.yahoo.com/yui/theater/video.php?v=crockonjs-3" rel="nofollow">video 3</a></u> at <strong>29&#8217;28&#8221;</strong>)</p>
<p>To me both make perfect sense, yet <strong>I choose to adhere to the standards proposed by Crockford</strong>.</p>
<p>The only important thing is to have the <strong>opening parenthesis</strong>, in order to not to have a <strong>function expression</strong> rather than a <strong>function statement</strong>. The statement would not be callable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jordi Boggiano</title>
		<link>http://pierrespring.com/2010/05/24/dirty-looping-in-javascript/comment-page-1/#comment-18</link>
		<dc:creator>Jordi Boggiano</dc:creator>
		<pubDate>Mon, 24 May 2010 14:56:20 +0000</pubDate>
		<guid isPermaLink="false">http://pierrespring.com/?p=78#comment-18</guid>
		<description>Interesting method. Just a note on using one-shot functions as you did, I usually saw the function wrapped in parenthesis&#039; and then executed, rather than the execute then wrap that you have there, so that would look like:
[cc lang=&quot;javascript&quot;](function(){
    //stuff
})();
[/cc]

I&#039;m not sure if there is a difference between the two as far as browser support goes or anything, but if the other induces errors, you may want to try that.</description>
		<content:encoded><![CDATA[<p>Interesting method. Just a note on using one-shot functions as you did, I usually saw the function wrapped in parenthesis&#8217; and then executed, rather than the execute then wrap that you have there, so that would look like:</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//stuff</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I&#8217;m not sure if there is a difference between the two as far as browser support goes or anything, but if the other induces errors, you may want to try that.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
