<?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>Adam Koch &#187; javascript</title>
	<atom:link href="http://www.adamkoch.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adamkoch.com</link>
	<description>Front-end Software Developer</description>
	<lastBuildDate>Tue, 24 Jan 2012 02:25:41 +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 Optimizations</title>
		<link>http://www.adamkoch.com/2010/11/24/javascript-optimizations/</link>
		<comments>http://www.adamkoch.com/2010/11/24/javascript-optimizations/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 15:05:07 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[closure]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[uglifyjs]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1881</guid>
		<description><![CDATA[I was looking at kangax&#8216;s suggestions for Google Closure compression techniques and I wanted to know how UglifyJS handled it. Input: var i = 10000, j = 0.1, k = /[\w]/, m = new Array(1, 2, 3); throw 0.1; Closure: var i=1E4,j=0.1,k=/[\w]/,m=[1,2,3];throw 0.1; UglifyJS: var i=1e4,j=.1,k=/[\w]/,m=new Array(1,2,3);throw.1 Interesting that UglifyJS doesn&#8217;t compress the Array declaration, [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at <a href="http://twitter.com/kangax">kangax</a>&#8216;s <a href="http://code.google.com/p/closure-compiler/issues/detail?id=36&amp;can=1&amp;q=increment&amp;colspec=ID%20Type%20Status%20Priority%20Component%20Owner%20Summary">suggestions</a> for <a href="http://code.google.com/closure/compiler/">Google Closure</a> compression techniques and I wanted to know how <a href="http://github.com/mishoo/UglifyJS/">UglifyJS</a> handled it.</p>
<p>Input:<code><br />
var i = 10000,<br />
j = 0.1,<br />
k = /[\w]/,<br />
m = new Array(1, 2, 3);<br />
throw 0.1;</code></p>
<p><a href="http://closure-compiler.appspot.com/home">Closure</a>:<br />
<code>var i=1E4,j=0.1,k=/[\w]/,m=[1,2,3];throw 0.1;</code></p>
<p><a href="http://marijnhaverbeke.nl/uglifyjs">UglifyJS</a>:<br />
<code>var i=1e4,j=.1,k=/[\w]/,m=new Array(1,2,3);throw.1</code></p>
<p>Interesting that <a href="http://github.com/mishoo/UglifyJS/">UglifyJS</a> doesn&#8217;t compress the Array declaration, but does compress 2 other statements that <a href="http://code.google.com/closure/compiler/">Google Closure</a> doesn&#8217;t/won&#8217;t.</p>
<p>In UglifyJS&#8217;s <a href="https://github.com/mishoo/UglifyJS/#readme">README</a> it states that Google Closure &#8220;runs terribly slow&#8221;. Why is this an issue? Won&#8217;t you only compress when pushing to prod?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2010/11/24/javascript-optimizations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>navigator.appVersion</title>
		<link>http://www.adamkoch.com/2010/02/05/navigator-appversion/</link>
		<comments>http://www.adamkoch.com/2010/02/05/navigator-appversion/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 20:24:53 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1844</guid>
		<description><![CDATA[Wow. This is messed up. Here is a table of the browsers I have at my disposal and the returned value from the JavaScript variable &#8220;navigator.appVersion&#8221;. Browser navigator.appVersion Chrome 5.0 5.0 Opera 10.00 9.80 IE 8.0 4.0 IE 7.0 4.0 IE 6.0 4.0 Safari 4.0 5.0 Safari 3.2 5.0 Firefox 3.6 5.0 Firefox 3.5 5.0 [...]]]></description>
			<content:encoded><![CDATA[<p>Wow. This is messed up. Here is a table of the browsers I have at my disposal and the returned value from the JavaScript variable &#8220;navigator.appVersion&#8221;.</p>
<table>
<tr>
<th>Browser</th>
<th>navigator.appVersion</th>
</tr>
<tr>
<td>Chrome 5.0</td>
<td>5.0</td>
</tr>
<tr>
<td>Opera 10.00</td>
<td>9.80</td>
</tr>
<tr>
<td>IE 8.0</td>
<td>4.0</td>
</tr>
<tr>
<td>IE 7.0</td>
<td>4.0</td>
</tr>
<tr>
<td>IE 6.0</td>
<td>4.0</td>
</tr>
<tr>
<td>Safari 4.0</td>
<td>5.0</td>
</tr>
<tr>
<td>Safari 3.2</td>
<td>5.0</td>
</tr>
<tr>
<td>Firefox 3.6</td>
<td>5.0</td>
</tr>
<tr>
<td>Firefox 3.5</td>
<td>5.0</td>
</tr>
<tr>
<td>Firefox 2.0</td>
<td>5.0</td>
</tr>
</table>
<p>Ok browser makers. Let&#8217;s start over. I don&#8217;t think any site is using the navigator.appVersion anymore so now is as good of time as ever to start fresh. What do you say?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2010/02/05/navigator-appversion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Won&#8217;t Assign Null</title>
		<link>http://www.adamkoch.com/2010/01/25/javascript-wont-assign-null/</link>
		<comments>http://www.adamkoch.com/2010/01/25/javascript-wont-assign-null/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 02:54:06 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tidbit]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1799</guid>
		<description><![CDATA[I didn&#8217;t know this! &#8220;The null value &#8230; can only be assigned by your code.&#8221; From Object-Oriented JavaScript by Stoyan Stefanov]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t know this!</p>
<p>&#8220;The <code>null</code> value &#8230; can only be assigned by your code.&#8221;<br />
From <a href="http://www.packtpub.com/object-oriented-javascript-applications-libraries/book">Object-Oriented JavaScript by Stoyan Stefanov</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2010/01/25/javascript-wont-assign-null/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Gotcha</title>
		<link>http://www.adamkoch.com/2010/01/24/javascript-gotcha/</link>
		<comments>http://www.adamkoch.com/2010/01/24/javascript-gotcha/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 02:48:18 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tidbit]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1795</guid>
		<description><![CDATA[This will alert &#8220;10&#8243;: var num = num &#124;&#124; 10; alert(num); But so will this: num = 0; var num = num &#124;&#124; 10; alert(num); Watch out for the cases where num is &#8220;falsey&#8220;.]]></description>
			<content:encoded><![CDATA[<p>This will alert &#8220;10&#8243;:<br />
<code>var num = num || 10;<br />
alert(num);</code></p>
<p>But so will this:<br />
<code>num = 0;<br />
var num = num || 10;<br />
alert(num);</code></p>
<p>Watch out for the cases where <code>num</code> is &#8220;<a href="http://www.adamkoch.com/2010/01/23/falsy-javascript/">falsey</a>&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2010/01/24/javascript-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Falsey (Falsy?) JavaScript</title>
		<link>http://www.adamkoch.com/2010/01/23/falsy-javascript/</link>
		<comments>http://www.adamkoch.com/2010/01/23/falsy-javascript/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 02:45:41 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tidbit]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1793</guid>
		<description><![CDATA[The following convert to false when applied to a double negation in JavaScript: "" null undefined 0 NaN]]></description>
			<content:encoded><![CDATA[<p>The following convert to false when applied to a double negation in JavaScript:<br />
<code>""<br />
null<br />
undefined<br />
0<br />
NaN</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2010/01/23/falsy-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Returning from a constructor</title>
		<link>http://www.adamkoch.com/2010/01/22/returning-from-a-constructor/</link>
		<comments>http://www.adamkoch.com/2010/01/22/returning-from-a-constructor/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 01:34:47 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tidbit]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1790</guid>
		<description><![CDATA[&#8220;&#8230; if you try to return anything [from a constructor] that is not an object [emphasis mine], the constructor will proceed with its usual behavior and return this.&#8221; From Object-Oriented JavaScript by Stoyan Stefanov]]></description>
			<content:encoded><![CDATA[<p>&#8220;&#8230; if you try to return anything [from a constructor] that is <em>not an object</em> [emphasis mine], the constructor will proceed with its usual behavior and return this.&#8221;<br />
From <a href="http://www.packtpub.com/object-oriented-javascript-applications-libraries/book">Object-Oriented JavaScript by Stoyan Stefanov</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2010/01/22/returning-from-a-constructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comments on Optimizing HTML</title>
		<link>http://www.adamkoch.com/2009/12/29/comments-on-optimizing-html/</link>
		<comments>http://www.adamkoch.com/2009/12/29/comments-on-optimizing-html/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 20:24:58 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[nitpick]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1724</guid>
		<description><![CDATA[I was reading Juriy Zaytsev&#8216;s (@kangax) article &#8220;Optimizing HTML&#8221; and had a few comments. 1. I have used &#60;!CDATA[...]&#62; sections when I&#8217;m embedding &#8220;&#60;&#8221; and &#8220;&#62;&#8221; but I think that&#8217;s just because I&#8217;ve used XSL before and they have caused problems when performing transformations. But I&#8217;ll try to remove it from my HTML as he [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading <a title="Juriy Zaytsev's website" href="http://perfectionkills.com/">Juriy Zaytsev</a>&#8216;s (<a title="kangax on Twitter" href="http://twitter.com/kangax">@kangax</a>) <a title="Optimizing HTML article" href="http://perfectionkills.com/optimizing-html/">article &#8220;Optimizing HTML&#8221;</a> and had a few comments.</p>
<p>1. I have used &lt;!CDATA[...]&gt; sections when I&#8217;m embedding &#8220;&lt;&#8221; and &#8220;&gt;&#8221; but I think that&#8217;s just because I&#8217;ve used XSL before and they have caused problems when performing transformations. But I&#8217;ll try to remove it from my HTML as he suggests.</p>
<p>2. If I don&#8217;t have a URL to use in the href attribute, I&#8217;ll still use &#8220;javascript:void(0)&#8221; because I really don&#8217;t like the hash being added to my URL. Perhaps I should just add some jQuery code:</p>
<p>$(&#8220;a[href='#']&#8220;).click(function(){return false;});</p>
<p>That&#8217;s 49 characters, so I would have to change only 3 links to use the hash instead of &#8220;javascript:void(0)&#8221; to save space.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2009/12/29/comments-on-optimizing-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Konami jQuery Plugin</title>
		<link>http://www.adamkoch.com/2009/10/20/konami-jquery-plugin/</link>
		<comments>http://www.adamkoch.com/2009/10/20/konami-jquery-plugin/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 02:31:05 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[konami]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1667</guid>
		<description><![CDATA[I found a jQuery plugin to add the Konami code to your website, but I think mine is better. Mine works in IE8. Here&#8217;s a demo.]]></description>
			<content:encoded><![CDATA[<p>I found a <a href="http://www.newmediacampaigns.com/page/konami-code-jquery-plugin-pointlessly-easy">jQuery plugin</a> to add the <a href="http://en.wikipedia.org/wiki/Konami_Code">Konami code</a> to your website, but I think <a href="http://www.adamkoch.com/konami.js">mine</a> is better. Mine works in IE8. Here&#8217;s a <a href="http://www.adamkoch.com/konami.html">demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2009/10/20/konami-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>White-space and character 160</title>
		<link>http://www.adamkoch.com/2009/07/25/white-space-and-character-160/</link>
		<comments>http://www.adamkoch.com/2009/07/25/white-space-and-character-160/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 19:41:42 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[160]]></category>
		<category><![CDATA[ascii]]></category>
		<category><![CDATA[char]]></category>
		<category><![CDATA[character]]></category>
		<category><![CDATA[character 160]]></category>
		<category><![CDATA[charCodeAt]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[trim]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1620</guid>
		<description><![CDATA[I came across a problem in Internet Explorer (it wasn&#8217;t a problem with Firefox) when I was trying to compare two strings. To me, one string looked to have an extra space in the front. No problem, I&#8217;ll just call the jQuery trim function. Well, that didn&#8217;t work. So I used charCodeAt and found it [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
.pass {
    background-color: #ADFFAD;
}
.fail {
    background-color: #FFADAD;
}
table#whitespacedata, 
table#whitespacedata tr,
table#whitespacedata tr td,
table#whitespacedata tr th {
    color: black;
    border: solid 1px black;
}
table#whitespacedata, 
table#whitespacedata tr,
table#whitespacedata tr td,
table#whitespacedata tr th {
    color: black;
    border: solid 1px black;
}
table#whitespacedata td,
table#whitespacedata th {
    padding: 3px;
}
</style>
<p>I came across a problem in Internet Explorer (it wasn&#8217;t a problem with Firefox) when I was trying to compare two strings. To me, one string looked to have an extra space in the front. No problem, I&#8217;ll just call the <a href="http://docs.jquery.com/Utilities/jQuery.trim#str">jQuery trim function</a>. Well, that didn&#8217;t work. So I used <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/charCodeAt">charCodeAt</a> and found it was ASCII character 160. I looked up <a title="char code 160" href="http://htmlhelp.com/reference/charset/iso160-191.html">char code 160</a> and saw that it is a &#8220;Non-breaking space&#8221;. You would think that a &#8220;space&#8221; character would be trimmed. I looked at the jQuery code that does the trimming and the grep pattern uses <code>\s</code>. So, evidently you can&#8217;t use <code>\s</code> to catch the &#8220;Non-breaking space&#8221; in IE. I wonder why no one else has seen this. I wrote up a <a href="/char160test.html">test page</a> to illustrate this.</p>
<p>To create the non-breaking space, you can use <code>String.fromCharCode(160)</code> or the Unicode representation &#8220;\u00A0&#8243;. &#8220;&amp;#160;&#8221; doesn&#8217;t seem to work when using regular expressions, although it behaves the same when printed.</p>
<table border="1" cellspacing="3" cellpadding="3" id="whitespacedata">
<tbody>
<tr style="background-color: #ADD6FF">
<th> Browser</th>
<th> Evaluates character 160 as white-space</th>
</tr>
<tr class="pass">
<td>Firefox 3, 3.5</td>
<td>Yes</td>
</tr>
<tr class="pass">
<td>Chrome 3.0</td>
<td>Yes</td>
</tr>
<tr class="fail">
<td>Internet Explorer 7, 8</td>
<td>No</td>
</tr>
<tr class="fail">
<td>Safari 3.2</td>
<td>No</td>
</tr>
<tr class="pass">
<td>Opera 9</td>
<td>Yes</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2009/07/25/white-space-and-character-160/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Peasant Multiplication</title>
		<link>http://www.adamkoch.com/2009/07/23/peasant-multiplication/</link>
		<comments>http://www.adamkoch.com/2009/07/23/peasant-multiplication/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 05:25:51 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Professional]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://www.adamkoch.com/?p=1595</guid>
		<description><![CDATA[Here&#8217;s my entry for the The Daily WTF&#8216;s Programming Praxis: Russian Peasant Multiplication: function peasant1(a, b) { var value = a &#38; 1 ? b : 0; while(a &#62; 1) { a &#62;&#62;= 1; b &#60;&#60;= 1; if (a &#38; 1) value += b; } return value; } function peasant2(a, b) { var value = [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s my entry for the <a href="http://thedailywtf.com/">The Daily WTF</a>&#8216;s <a href="http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx">Programming Praxis: Russian Peasant Multiplication</a>:</p>
<pre>function peasant1(a, b) {
  var value = a &amp; 1 ? b : 0;
  while(a &gt; 1) {
    a &gt;&gt;= 1;
    b &lt;&lt;= 1;
    if (a &amp; 1)
      value += b;
  }
  return value;
}

function peasant2(a, b) {
  var value = a &amp; 1 ? b : 0;
  if(a &gt; 1)
    value += peasant2(a &gt;&gt; 1, b &lt;&lt; 1);
  return value;
}

function peasant3(a, b) {
  return a &gt; 1 ? (a &amp; 1 ? b : 0) + peasant3(a &gt;&gt; 1, b &lt;&lt; 1) : a &amp; 1 ? b : 0;
}

function peasant4(a, b) {
  return a &amp; 1 ? value = a &gt; 1 ? value = b + peasant4(a &gt;&gt; 1, b &lt;&lt; 1) : b : value = peasant4(a &gt;&gt; 1, b &lt;&lt; 1);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.adamkoch.com/2009/07/23/peasant-multiplication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

