<?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>updownleftright.net</title>
	<atom:link href="http://updownleftright.net/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://updownleftright.net/blog</link>
	<description>updownleftright</description>
	<lastBuildDate>Fri, 30 Sep 2011 22:14:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Javascript tip of the day &#8211; Restoring a broken console.log function (Magento)</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-restoring-console-log-on-a-magento-site</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-restoring-console-log-on-a-magento-site#comments</comments>
		<pubDate>Fri, 30 Sep 2011 22:11:40 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=160</guid>
		<description><![CDATA[This one is very specific, but hopefully useful to someone. If you&#8217;ve ever developed a site using ecommerce platform Magento, you might have discovered that console.log doesn&#8217;t work. It seems that some other code has hijacked the function and swallows all the output. This can be hugely frustrating if you are trying to debug some [...]]]></description>
			<content:encoded><![CDATA[<p>This one is very specific, but hopefully useful to someone.</p>
<p>If you&#8217;ve ever developed a site using ecommerce platform Magento, you might have discovered that console.log doesn&#8217;t work. It seems that some other code has hijacked the function and swallows all the output. This can be hugely frustrating if you are trying to debug some javascript code, but luckily there is a clever way to restore the functionality.</p>
<p>The quick version: Use this code (on document ready) and it will start working again.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">console</span> <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;iframe&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">contentWindow</span>.<span style="color: #660066;">console</span><span style="color: #339933;">;</span></pre></div></div>

<p>The more detailed explanation of what is happening in the above code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// create a new iframe</span>
<span style="color: #003366; font-weight: bold;">var</span> frame <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;iframe&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// hide it before adding it to the document so it has no visible effect</span>
frame.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// add it, this causes the frame to initialise correctly, and gain it's own window object</span>
frame.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// get the base (non-jQuery) element</span>
frame <span style="color: #339933;">=</span> frame<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// get the iframes window object</span>
otherWindow <span style="color: #339933;">=</span> frame.<span style="color: #660066;">contentWindow</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// replace this windows console with the other windows console</span>
window.<span style="color: #660066;">console</span> <span style="color: #339933;">=</span> otherWindow.<span style="color: #660066;">console</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-restoring-console-log-on-a-magento-site/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day &#8211; jQuery Live events</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-live-events</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-live-events#comments</comments>
		<pubDate>Thu, 29 Sep 2011 07:10:06 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=115</guid>
		<description><![CDATA[When you attach an event to a collection of elements using jQuery, the event will only affect elements which exist at that moment in time. For example: // affects all matching elements which exist now $&#40;'.alreadyExists'&#41;.click&#40;someFunction&#41;; &#160; // this element will not have an onclick event $&#40;newElement&#41;.addClass&#40;'alreadyExists'&#41;; In this scenario, if you wanted to add [...]]]></description>
			<content:encoded><![CDATA[<p>When you attach an event to a collection of elements using jQuery, the event will only affect elements which exist at that moment in time. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// affects all matching elements which exist now</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.alreadyExists'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>someFunction<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// this element will not have an onclick event</span>
$<span style="color: #009900;">&#40;</span>newElement<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alreadyExists'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this scenario, if you wanted to add the event to the new element, you would need another line of code adding the click event to the element.</p>
<p>If you find yourself in this situation, you should try using jQuerys &#8220;Live&#8221; event handler instead. It provides a way of ataching events to all current <em>and future</em> elements which match the given selector. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// works for elements created later</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.mightExist'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> someFunction<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// as soon as the class is added, the element also gets the onclick event handler</span>
$<span style="color: #009900;">&#40;</span>newElement<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mightExist'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-live-events/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day &#8211; Using the ternary operator</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-using-the-ternary-operator</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-using-the-ternary-operator#comments</comments>
		<pubDate>Tue, 27 Sep 2011 07:31:18 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=145</guid>
		<description><![CDATA[The ternary operator is a nice alternative to more long winded if/else clauses that can really help the readability to your code. For example: // instead of writing something like if&#40;b &#60; 2&#41; &#123; a = c; &#125; else &#123; a = d; &#125; &#160; // you can use var a = &#40;b &#60; 2&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>The ternary operator is a nice alternative to more long winded if/else clauses that can really help the readability to your code. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// instead of writing something like</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>b <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	a <span style="color: #339933;">=</span> c<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
	a <span style="color: #339933;">=</span> d<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// you can use </span>
<span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>b <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> c <span style="color: #339933;">:</span> d<span style="color: #339933;">;</span></pre></div></div>

<p>If that looks confusing, it might be more easily understood with the following:</p>
<blockquote><p>variable = test ? value if true : value if false;</p></blockquote>
<p>Essentially what happens is: the condition is tested, and one of two values is returned, depending on whether the condition was true or false. </p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-using-the-ternary-operator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day &#8211; making new elements with jQuery</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-making-new-elements-with-jquery</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-making-new-elements-with-jquery#comments</comments>
		<pubDate>Mon, 26 Sep 2011 07:30:36 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=137</guid>
		<description><![CDATA[Did you know you can not only select existing DOM elements with jQuery&#8217;s all powerful $ function, but you can also create brand new ones? For example: // core javascript var myDiv = document.createElement&#40;'div'&#41;; // jQuery version var myDiv = $&#40;'&#60;div&#62;'&#41;; You can also add all the usual attributes, and they will get parsed and [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know you can not only select existing DOM elements with jQuery&#8217;s all powerful $ function, but you can also create brand new ones? For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// core javascript</span>
<span style="color: #003366; font-weight: bold;">var</span> myDiv <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// jQuery version</span>
<span style="color: #003366; font-weight: bold;">var</span> myDiv <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>You can also add all the usual attributes, and they will get parsed and created alongside the element itself, although it is also perfectly possible to just chain normal jQuery methods onto the element creation for the same results.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myDiv <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div class=&quot;myClass&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// is functionally identical to:</span>
<span style="color: #003366; font-weight: bold;">var</span> myDiv <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-making-new-elements-with-jquery/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day &#8211; easy fallback method for when javascript is unavailable</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-easy-fallback-method-for-when-javascript-is-unavailable</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-easy-fallback-method-for-when-javascript-is-unavailable#comments</comments>
		<pubDate>Sun, 25 Sep 2011 17:32:44 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=128</guid>
		<description><![CDATA[If you ever have to deal with the possibility of visitors to your page having Javascript disabled (which you should, however unlikely it may seem), here is a dead simple method of detecting the lack of javascript and altering your page styles accordingly. First you need to add a class to the pages body tag, [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever have to deal with the possibility of visitors to your page having Javascript disabled (which you should, however unlikely it may seem), here is a dead simple method of detecting the lack of javascript and altering your page styles accordingly.</p>
<p>First you need to add a class to the pages body tag, something to signify a lack of javascript, so I use &#8216;nojs&#8217;.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;body class=&quot;nojs&quot;&gt;</pre></div></div>

<p>Then you need a bit of javascript to remove that class from the tag, here I am using jQuery, but you can use whatever you like, as long as it has the same effect. This needs to happen ASAP, so either stick a script tag immediately after the opening body tag, or use document ready.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'nojs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Once those two bits are in place, you can start adding styles which cater for the lack of javascript simply by using the &#8216;.nojs&#8217; selector. Any element which matches must by definition on a page in which the javascript to remove the class has not run, and you can safely assume there is no javascript at all (or at least you can if your class removal code is solid, which is why I would recommend jQuery).</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.nojs</span> <span style="color: #6666ff;">.myclass</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.nojs</span> <span style="color: #6666ff;">.myotherclass</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The two examples above show the sort of thing you can use this for, such as to display a element which would otherwise be revealed by javascript, or to move something into view which would normally be animated by javascript.</p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-easy-fallback-method-for-when-javascript-is-unavailable/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day – jQuery document ready shortcuts</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-document-ready-shortcuts</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-document-ready-shortcuts#comments</comments>
		<pubDate>Sat, 24 Sep 2011 09:55:00 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=120</guid>
		<description><![CDATA[Everyone who has used jQuery for longer than a few minutes is probably aware of the document ready function: $&#40;document&#41;.ready&#40;function&#40;&#41;&#123;     // do something &#125;&#41;; By wrapping your code up like that you guarantee that any html elements you need to reference have actually been created and are ready for manipulation. Simple enough, but there&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone who has used jQuery for longer than a few minutes is probably aware of the document ready function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><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>
    <span style="color: #006600; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By wrapping your code up like that you guarantee that any html elements you need to reference have actually been created and are ready for manipulation. Simple enough, but there&#8217;s actually an even simpler way of doing the same thing:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<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>
    <span style="color: #006600; font-style: italic;">// this works exactly the same</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Handy eh? Also, because all you&#8217;re really doing is passing in a function, it doesn&#8217;t have to be anonymous like in the above examples. Try passing in a reference to an existing function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> startup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do stuff</span>
<span style="color: #009900;">&#125;</span>
$<span style="color: #009900;">&#40;</span>startup<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The startup function will then be called on document ready, but could also be called separately if needed.</p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-document-ready-shortcuts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day – More efficient for loops</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-more-efficient-for-loops</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-more-efficient-for-loops#comments</comments>
		<pubDate>Fri, 23 Sep 2011 07:15:35 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=109</guid>
		<description><![CDATA[Instead of doing something this: // normal way to loop through an array for&#40;i = 0; i &#60; myArray.length; i++&#41; &#123; // do something &#125; Try this slightly modified syntax: // declaring variables properly helps keep the global scope clean // but more importantly, assigning the length to a variable and testing that instead means [...]]]></description>
			<content:encoded><![CDATA[<p>Instead of doing something this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// normal way to loop through an array</span>
<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> myArray.<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>
    <span style="color: #006600; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Try this slightly modified syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// declaring variables properly helps keep the global scope clean</span>
<span style="color: #006600; font-style: italic;">// but more importantly, assigning the length to a variable and testing that instead means</span>
<span style="color: #006600; font-style: italic;">// that the array length is only calculated at the start, not once per iteration</span>
<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// do something slightly faster</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>It&#8217;s a small change, but if you have a lot of loops, or work with very large arrays, it can soon add up.</p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-more-efficient-for-loops/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript tip of the day – jQuery noConflict mode</title>
		<link>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-noconflict-mode</link>
		<comments>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-noconflict-mode#comments</comments>
		<pubDate>Thu, 22 Sep 2011 10:04:00 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Javascript tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=101</guid>
		<description><![CDATA[If you ever have multiple scripts on a page which use the $ variable (such as prototype), you can use the jQuery&#8217;s handy noConflict method to tell it to give up control of $, allowing the other library to use it instead. For example: // will not work because $ is conflicting $&#40;'.myClass'&#41;.show&#40;&#41;; &#160; // [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever have multiple scripts on a page which use the $ variable (such as prototype), you can use the jQuery&#8217;s handy noConflict method to tell it to give up control of $, allowing the other library to use it instead. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// will not work because $ is conflicting</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myClass'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// tell jQuery to play nice</span>
jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// will (probably) not work because $ is not longer a reference to jQuery</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myClass'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// will work instead</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myClass'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Interestingly, the noConflict method returns a reference to the jQuery object, so there is nothing stopping you deciding on your own variable for future jQuery calls, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// assign the result to a variable</span>
<span style="color: #003366; font-weight: bold;">var</span> jq <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// jq is now functionally identical to jQuery, so this works</span>
jq<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myClass'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Not earth shatteringly useful I admit, but seeing as part of the attraction of jQuery is the brevity of it&#8217;s code, having to use &#8220;jQuery&#8221; everywhere can be quite annoying, which this nicely sidesteps.</p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/09/javascript-tip-of-the-day-jquery-noconflict-mode/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Game &#8211; 8bit roguelike</title>
		<link>http://updownleftright.net/blog/2011/06/javascript-game-8bit-roguelike</link>
		<comments>http://updownleftright.net/blog/2011/06/javascript-game-8bit-roguelike#comments</comments>
		<pubDate>Sat, 25 Jun 2011 15:23:00 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=88</guid>
		<description><![CDATA[After a long gap I have returned to the world of Javascript game development with a new project, this time an 8bit roguelike (all done with HTML5 canvas). I&#8217;m trying to keep this one simple so I can actually finish it, so it&#8217;s very old school, purely tile based, no animation, no physics, which hopefully [...]]]></description>
			<content:encoded><![CDATA[<p>After a long gap I have returned to the world of Javascript game development with a new project, this time an 8bit roguelike (all done with HTML5 canvas).</p>
<p>I&#8217;m trying to keep this one simple so I can actually finish it, so it&#8217;s very old school, purely tile based, no animation, no physics, which hopefully should enable me to concentrate on the game itself.</p>
<p>At the moment it&#8217;s pretty much just a proof of concept, it loads some map data, and you can walk around on it and bump into a few walls and objects. </p>
<p><span id="more-88"></span></p>
<p>Have a go (its embedded below)  use wasd or the arrow keys to move around and leave a comment if you have any suggestions. </p>
<p><script src="/experiments/8rogue/1/js/__COMPILED.js"></script><br />
<canvas id="game1"></canvas><br />
<script type="text/javascript">// <![CDATA[
startup('game1')
// ]]&gt;</script></p>
<p>More to come in the next few days!</p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/06/javascript-game-8bit-roguelike/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>List of Company Colors</title>
		<link>http://updownleftright.net/blog/2011/01/lis-of-company-colours</link>
		<comments>http://updownleftright.net/blog/2011/01/lis-of-company-colours#comments</comments>
		<pubDate>Mon, 10 Jan 2011 22:28:48 +0000</pubDate>
		<dc:creator>beeglebug</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.udlr.net/blog/?p=83</guid>
		<description><![CDATA[I&#8217;ve just updated the list of company colors (udlr.net/list_of_company_colors), adding a few companies like Facebook and Twitter, and changing the design to fit the new look round here.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just updated the list of company colors (<a href="http://udlr.net/list_of_company_colors">udlr.net/list_of_company_colors</a>), adding a few companies like Facebook and Twitter, and changing the design to fit the new look round here.</p>
]]></content:encoded>
			<wfw:commentRss>http://updownleftright.net/blog/2011/01/lis-of-company-colours/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

