<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>brian.peiris.name</title>
	<atom:link href="http://brian.peiris.name/feed/" rel="self" type="application/rss+xml" />
	<link>http://brian.peiris.name</link>
	<description></description>
	<lastBuildDate>Thu, 17 Mar 2011 21:04:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Defining JavaScript functions inside a loop</title>
		<link>http://brian.peiris.name/2011/03/defining-javascript-functions-inside-a-loop/</link>
		<comments>http://brian.peiris.name/2011/03/defining-javascript-functions-inside-a-loop/#comments</comments>
		<pubDate>Thu, 17 Mar 2011 19:16:00 +0000</pubDate>
		<dc:creator>brianpeiris</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://brian.peiris.name/?p=6</guid>
		<description><![CDATA[One of the warnings that JSLint (and JSHint) can output is &#8220;Don&#8217;t make functions within a loop&#8221;. JSLint doesn&#8217;t provide any further information about the warning and a quick web-search only results in mentions of best-practice and wasting of resources. I preferred to see actual stats so I wrote up a small test using JSLitmus [...]]]></description>
			<content:encoded><![CDATA[<p>One of the warnings that <a href="http://jslint.com/" target="_blank">JSLint</a> (and <a href="http://jshint.com/" target="_blank">JSHint</a>) can output is &#8220;Don&#8217;t make functions within a loop&#8221;. JSLint doesn&#8217;t provide any further information about the warning and a quick web-search only results in mentions of best-practice and wasting of resources.<span id="more-6"></span> I preferred to see actual stats so I wrote up <a href="http://brian.peiris.name/demos/functionInsideLoopTest.html" target="_blank">a small test</a> using <a href="http://www.broofa.com/Tools/JSLitmus/" target="_blank">JSLitmus</a> to benchmark the difference between defining a function inside a loop, outside a loop, outside a function and outside a function with a local reference. I&#8217;m not sure why Chrome suffers a drastic performance decrease when using a local reference to a global function but at least this provides some solid data for obeying the warning:</p>
<div class="wp-caption alignleft" style="width: 260px"><a href="http://tinyurl.com/67yszxg"><img class="  " title="Firefox 4 RC" src="http://tinyurl.com/67yszxg" alt="" width="250" height="150" /></a><p class="wp-caption-text">Firefox 4 RC</p></div>
<div class="wp-caption alignleft" style="width: 260px"><a href="http://tinyurl.com/4kbx6fk"><img class="  " title="Google Chrome 10.0" src="http://tinyurl.com/4kbx6fk" alt="" width="250" height="150" /></a><p class="wp-caption-text">Google Chrome 10.0</p></div>
<div class="wp-caption alignleft" style="width: 260px"><a href="http://tinyurl.com/4govuy2"><img class=" " title="Internet Explorer 9" src="http://tinyurl.com/4govuy2" alt="" width="250" height="150" /></a><p class="wp-caption-text">Internet Explorer 9</p></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://brian.peiris.name/2011/03/defining-javascript-functions-inside-a-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

