<?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>David B. Calhoun - Developer Blog</title>
	<atom:link href="http://davidbcalhoun.com/feed" rel="self" type="application/rss+xml" />
	<link>http://davidbcalhoun.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 03 Mar 2010 16:38:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Clockwork Box</title>
		<link>http://davidbcalhoun.com/2010/a-clockwork-box</link>
		<comments>http://davidbcalhoun.com/2010/a-clockwork-box#comments</comments>
		<pubDate>Tue, 02 Mar 2010 23:22:59 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[box model]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=171</guid>
		<description><![CDATA[
With CSS there are always various ways to accomplish something.  After reading this short tidbit, you should be familiar with the various ways of controlling the size of an element&#8217;s padding, border, and margin, and you should know what the handy &#8220;clockwork&#8221; tip is, and how it will be useful to remember when you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<div class="intro"><img src="http://davidbcalhoun.com/wp-content/uploads/2010/03/clockwork-box.png" alt="Clockwork Orange cover" title="Clockwork Orange cover" width="450" height="320" class="left alignleft size-full wp-image-174" />
<div>With CSS there are always various ways to accomplish something.  After reading this short tidbit, you should be familiar with the various ways of controlling the size of an element&#8217;s padding, border, and margin, and you should know what the handy &#8220;clockwork&#8221; tip is, and how it will be useful to remember when you&#8217;re putting your CSS into practice.</div>
</div>
<h3>Equal values on all four sides</h3>
<p>If all four values (top, right, bottom, and left) are equal, then you simply write the following:</p>
<pre name="code" class="css">
padding: 1px;
border-width: 1px;
margin: 1px;
</pre>
<h3>The longhand way</h3>
<p>If you don&#8217;t want equal values on all four sides, then you can specify each side individually:</p>
<pre name="code" class="css">
padding-top: 1px;
padding-right: 2px;
padding-bottom: 3px;
padding-left: 4px;

border-top-width: 1px;
border-right-width: 2px;
border-bottom-width: 3px;
border-left-width: 4px;

margin-top: 1px;
margin-right: 2px;
margin-bottom: 3px;
margin-left: 4px;
</pre>
<h3>The shortcut (like clockwork)</h3>
<p>However this seems to be quite a hassle typing out each property, so you&#8217;ll find it&#8217;s much easier to use the following shorthand, which is in this order: top, right, bottom, left (think of the hands going clockwise around a clock).  The following is equivalent to the above code:</p>
<pre name="code" class="css">
padding: 1px 2px 3px 4px;
border-width: 1px 2px 3px 4px;
margin: 1px 2px 3px 4px;
</pre>
<h3>Other shorthands</h3>
<p>This is the style I find myself writing in most often, but there are two other shorthand styles you should be aware of:</p>
<pre name="code" class="css">
padding: 1px 2px 3px;  /* top, left/right, bottom */
padding: 1px 2px;      /* top/bottom, left/right */
</pre>
<h3>Summary</h3>
<p>In short, there are various ways to define the padding, border, and margin on an element.  Here&#8217;s a recap, with padding used as an example:</p>
<pre name="code" class="css">
padding: 1px;              /* 1 value: top/right/bottom/left     */
padding: 1px 2px;          /* 2 values: top/bottom, left/right   */
padding: 1px 2px 3px;      /* 3 values: top, left/right, bottom  */
padding: 1px 2px 3px 4px;  /* 4 values: top, right, bottom, left */
</pre>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2010/a-clockwork-box/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for the week of February 21, 2010</title>
		<link>http://davidbcalhoun.com/2010/links-for-the-week-of-february-21-2010</link>
		<comments>http://davidbcalhoun.com/2010/links-for-the-week-of-february-21-2010#comments</comments>
		<pubDate>Sun, 28 Feb 2010 19:00:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=164</guid>
		<description><![CDATA[General links

Video: Flash performance on the Nexus One
censorzilla
PHP compiler performance &#8211; PHP Classes blog

Mobile

10 Great Tools to Create a Mobile Version of Your Site

]]></description>
			<content:encoded><![CDATA[<h3>General links</h3>
<ul class="links">
<li><a href="http://www.bytearray.org/?p=1470">Video: Flash performance on the Nexus One</a></li>
<li><a href="http://www.jwz.org/doc/censorzilla.html">censorzilla</a></li>
<li><a href="http://www.phpclasses.org/blog/post/117-PHP-compiler-performance.html">PHP compiler performance &#8211; PHP Classes blog</a></li>
</ul>
<h3>Mobile</h3>
<ul class="links">
<li><a href="http://spyrestudios.com/10-great-tools-to-create-a-mobile-version-of-your-site/">10 Great Tools to Create a Mobile Version of Your Site</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2010/links-for-the-week-of-february-21-2010/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for the week of February 14, 2010</title>
		<link>http://davidbcalhoun.com/2010/links-for-the-week-of-february-14-2010</link>
		<comments>http://davidbcalhoun.com/2010/links-for-the-week-of-february-14-2010#comments</comments>
		<pubDate>Sun, 21 Feb 2010 19:00:32 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=128</guid>
		<description><![CDATA[General links

What really happens when you navigate to a URL &#8211; great in-depth explanation of computer-to-server transactions.  With pictures!
(Google) Update on Qualified Developer Program &#8211; some insight into the motivation behind Google&#8217;s Qualified Developer Program

HTML5/CSS3 and new web technology

I Can&#8217;t Believe It&#8217;s Not Flash: Thomas Fuchs&#8217;s slides from his presentation at Webstock 2010
You Can [...]]]></description>
			<content:encoded><![CDATA[<h3>General links</h3>
<ul class="links">
<li><a href="http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/">What really happens when you navigate to a URL</a> &#8211; great in-depth explanation of computer-to-server transactions.  With pictures!</a>
<li><a href="http://googlegeodevelopers.blogspot.com/2010/02/update-on-qualified-developer-program.html">(Google) Update on Qualified Developer Program</a> &#8211; some insight into the motivation behind <a href="http://code.google.com/qualify/">Google&#8217;s Qualified Developer Program</a></li>
</ul>
<h3>HTML5/CSS3 and new web technology</h3>
<ul class="links">
<li><a href="http://www.slideshare.net/madrobby/i-cant-believe-its-not-flash">I Can&#8217;t Believe It&#8217;s Not Flash: Thomas Fuchs&#8217;s slides from his presentation at Webstock 2010</a></li>
<li><a href="http://designinformer.com/use-css3-now/">You Can Use CSS3 Right Now</a></li>
<li><a href="http://devsnippets.com/article/designing-with-html5-css3.html">Designing for the Future with HTML5+CSS3 : Tutorials and Best Practices</a></li>
</ul>
<h3>Mobile</h3>
<ul class="links">
<li><a href="http://www.engadget.com/2010/02/17/windows-phone-7-series-everything-you-ever-wanted-to-know/?s=t5">Windows Phone 7 Series: everything you ever wanted to know</a> &#8211; many details on Microsoft&#8217;s new phone OS announced this week.</li>
<li><a href="http://www.engadget.com/2010/02/16/rim-demos-new-webkit-based-blackberry-browser-at-mwc-its-fas/">RIM demos new WebKit-based BlackBerry browser at MWC &#8212; it&#8217;s fast!</a> &#8211; BlackBerry also had an announcement of their own: their new Webkit-based browser in development since their acquisition of Torch Mobile.  Torch was developing the <a href="http://en.wikipedia.org/wiki/Iris_Browser">Iris Browser</a>, which was one of the few browsers to score 100/100 on the Acid3 test.  Its JavaScript engine was WebKit&#8217;s Nitro (aka SquirrelFish Extreme (SFX), formerly known as JavaScriptCore)</li>
</ul>
<h3>Videos</h3>
<h4>BlackBerry showing off its new WebKit Browser</h4>
<p><object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/iD-FqvXVl3U&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/iD-FqvXVl3U&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object></p>
<h4>Engadget&#8217;s hands-on demo of Windows Phone 7 Series</h4>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="265" id="viddler"><param name="movie" value="http://www.viddler.com/simple_on_site/ee4dd83c" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="fake=1"/><embed src="http://www.viddler.com/simple_on_site/ee4dd83c" width="437" height="265" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" flashvars="fake=1" name="viddler" ></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2010/links-for-the-week-of-february-14-2010/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overall iPhone browser traffic share is decreasing (Jan2009 to Jan2010)</title>
		<link>http://davidbcalhoun.com/2010/iphone-traffic-decreasing-jan2009-to-jan2010</link>
		<comments>http://davidbcalhoun.com/2010/iphone-traffic-decreasing-jan2009-to-jan2010#comments</comments>
		<pubDate>Thu, 18 Feb 2010 09:36:02 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=136</guid>
		<description><![CDATA[According to the statistics available on statcounter.com, from January 2009 to January 2010, iPhone browser traffic share actually decreased, not increased, as one might expect.
This is likely due to new competition from Android phones, as well as the possibility that more users are simply using iPhone native apps instead of web apps.
In any case, in [...]]]></description>
			<content:encoded><![CDATA[<p>According to the statistics available on <a href="http://gs.statcounter.com/#mobile_browser-ww-monthly-200901-201001">statcounter.com</a>, from January 2009 to January 2010, iPhone browser traffic share actually <em>decreased</em>, not increased, as one might expect.</p>
<p>This is likely due to new competition from Android phones, as well as the possibility that more users are simply using iPhone <em>native</em> apps instead of web apps.</p>
<p>In any case, in my opinion <em>these</em> are the figures we ought to be looking at, not overall phone sales, as others such as <a href="http://www.quirksmode.org/blog/archives/2010/02/the_iphone_obse.html">PPK</a> concentrate on.  If we don&#8217;t use computer sales as an estimate of desktop browser share, then why should we use phone sales as an estimate of mobile browser share?  Just because someone has a phone with a pre-installed browser doesn&#8217;t lead them to actually use it.</p>
<p>In any case, here&#8217;s the statistics, with a few surprises:</p>
<ul>
<li>iPhone/iTouch web traffic share decreased in the US and worldwide</li>
<li>BlackBerry gained market share</li>
<li>NetFront gained market share (this somewhat baffled me)</li>
</ul>
<p>And now for the stats&#8230;</p>
<div class="percentages">
<h3>Worldwide mobile browser traffic (% share)</h3>
<table>
<thead>
<tr>
<td>Device</td>
<td>2009 %</td>
<td>2010 %</td>
<td>% change</td>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td>Opera</td>
<td>24.69</td>
<td>25.53</td>
<td class="positive">+0.84</td>
</tr>
<tr>
<td>iPhone</td>
<td>23.06</td>
<td>21.52</td>
<td class="negative">-1.54</td</tr>
<tr>
<td>Nokia</td>
<td>17.78</td>
<td>18.53</td>
<td class="positive">+1.75</td</tr>
<tr>
<td>iTouch</td>
<td>12.89</td>
<td>11.6</td>
<td class="negative">-1.29</td</tr>
<tr>
<td>BlackBerry</td>
<td>4.91</td>
<td>9.85</td>
<td class="positive">+4.94</td</tr>
<tr>
<td>Android</td>
<td>1.92</td>
<td>4.54</td>
<td class="positive">+2.62</td</tr>
<tr>
<td>NetFront</td>
<td>1.35</td>
<td>3.27</td>
<td class="positive">+1.92</td</tr>
<tr>
<td>Sony PSP</td>
<td>4.38</td>
<td>1.2</td>
<td class="negative">-3.18</td</tr>
<tr>
<td>Openwave</td>
<td>2.61</td>
<td>0.97</td>
<td class="negative">-1.64</td</tr>
<tr>
<td>(Other)</td>
<td>6.41</td>
<td>2.98</td>
<td class="negative">-3.43</td</tr>
</tbody>
</table>
</div>
<div class="percentages">
<h3>US mobile browser traffic (% share)</h3>
<table>
<thead>
<tr>
<td>Device</td>
<td>2009 %</td>
<td>2010 %</td>
<td>% change</td>
</tr>
</thead>
<tfoot></tfoot>
<tbody>
<tr>
<td>iPhone</td>
<td>37.01</td>
<td>32.96</td>
<td class="negative">-4.05</td>
</tr>
<tr>
<td>iTouch</td>
<td>23.49</td>
<td>20.62</td>
<td class="negative">-2.87</td</tr>
<tr>
<td>BlackBerry</td>
<td>11.37</td>
<td>19.32</td>
<td class="positive">+7.95</td</tr>
<tr>
<td>Android</td>
<td>5.19</td>
<td>11.9</td>
<td class="positive">+6.71</td</tr>
<tr>
<td>Sony PSP</td>
<td>7.68</td>
<td>2.18</td>
<td class="negative">-5.5</td</tr>
<tr>
<td>Opera</td>
<td>3.56</td>
<td>3.06</td>
<td class="negative">-0.5</td</tr>
<tr>
<td>Openwave</td>
<td>3.07</td>
<td>2.04</td>
<td class="negative">-1.03</td</tr>
<tr>
<td>NetFront</td>
<td>1</td>
<td>2.26</td>
<td class="positive">+1.26</td</tr>
<tr>
<td>IEMobile</td>
<td>3.12</td>
<td>0.74</td>
<td class="negative">-2.38</td</tr>
<tr>
<td>(Other)</td>
<td>4.5</td>
<td>4.92</td>
<td class="positive">+0.42</td</tr>
</tbody>
</table>
</div>
<p>Predictions for 2010:</p>
<ul>
<li>Android continues to increase market share</li>
<li>Decrease in NetFront market share (opposite of current trend)</li>
<li>Microsoft Windows Phone 7 Series reverses downward IE trend</li>
<li>iPad grows in market share (this is a given, but will it break the top 10?)</li>
</ul>
<p>Source: <a href="http://gs.statcounter.com/#mobile_browser-ww-monthly-200901-201001">statcounter.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2010/iphone-traffic-decreasing-jan2009-to-jan2010/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links for the week of February 7, 2010</title>
		<link>http://davidbcalhoun.com/2010/links-for-the-week-of-february-7-2010</link>
		<comments>http://davidbcalhoun.com/2010/links-for-the-week-of-february-7-2010#comments</comments>
		<pubDate>Mon, 15 Feb 2010 20:51:43 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=118</guid>
		<description><![CDATA[General links

Video for Everybody!: cross-browser support of HTML5 video and methods of fallback
Oracle Cuts Affect GNOME Accessibility Work: &#8220;&#8230;as a result of the layoffs &#8230; &#8216;the accessibility of the GNOME desktop will become the open source equivalent of an unfunded mandate, doomed ultimately to fail&#8217; &#8230;&#8221;
Google Acquires Aardvark For $50 million
&#8220;the latest publication of HTML5 [...]]]></description>
			<content:encoded><![CDATA[<h3>General links</h3>
<ul class="links">
<li><a href="http://camendesign.com/code/video_for_everybody">Video for Everybody!</a>: cross-browser support of HTML5 video and methods of fallback</li>
<li><a href="http://ostatic.com/blog/oracle-cuts-affect-gnome-accessibility-work">Oracle Cuts Affect GNOME Accessibility Work</a>: &#8220;&#8230;as a result of the layoffs &#8230; &#8216;the accessibility of the GNOME desktop will become the open source equivalent of an unfunded mandate, doomed ultimately to fail&#8217; &#8230;&#8221;</li>
<li><a href="http://techcrunch.com/2010/02/11/google-acquires-aardvark-for-50-million/">Google Acquires Aardvark For $50 million</a></li>
<li><a href="http://ln.hixie.ch/?start=1265967771&#038;count=1">&#8220;the latest publication of HTML5 is now blocked by Adobe, via an objection that has still not been made public (despite yesterday&#8217;s promise to make it so)&#8221;</a></li>
<li><a href="http://www.quirksmode.org/blog/archives/2010/02/the_iphone_obse.html">The iPhone obsession (QuirksMode)</a></li>
</ul>
<h3>Performance</h3>
<ul class="links">
<li><a href="http://ajaxian.com/archives/domtiming-interface-being-implemented-in-chromium-and-firefox">DOMTiming interface being implemented in Chromium and Firefox</a></li>
<li><a href="http://carlos.bueno.org/2010/02/measuring-javascript-parse-and-load.html">A Hidden Cost of Javascript</a>: file size is a factor in performance, but so is parse and load time</li>
<li><a href="http://www.nczonline.net/blog/2010/02/09/announcing-high-performance-javascript/">Announcing High Performance JavaScript</a>: Nicholas Zakas announces his latest book, due in March 2010.</li>
</ul>
<h3>Events</h3>
<ul class="links">
<li><a href="http://www.youtube.com/watch?v=JuThg91-4Nw">Video: Google Buzz Launch Event</a></li>
<li><a href="http://github.com/voodootikigod/jsconfus/commit/7e29a4b9afb80967775b3446153fc999edbd9ee7">JSConf speaker lineup?</a>: Apparently pictures from JSConf 2010&#8217;s speaker lineup (via <a href="http://twitter.com/jdalton/status/9043607765">John-David Dalton&#8217;s twitter</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2010/links-for-the-week-of-february-7-2010/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A primer on CSS colors</title>
		<link>http://davidbcalhoun.com/2009/a-primer-on-css-colors</link>
		<comments>http://davidbcalhoun.com/2009/a-primer-on-css-colors#comments</comments>
		<pubDate>Wed, 30 Dec 2009 05:17:41 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[rgb]]></category>
		<category><![CDATA[rgba]]></category>
		<category><![CDATA[web safe]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=85</guid>
		<description><![CDATA[Color keywords
Example usage:
// Example
body { color: red; }

// Generalization (not actual code)
body { color: color_name; }
Because color names are easy to remember, they&#8217;re handy for getting quick results, especially while doing rapid prototyping.
W3C&#8217;s CSS1 recommendation first mentioned 16 color keywords that you can use: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, [...]]]></description>
			<content:encoded><![CDATA[<h3>Color keywords</h3>
<p>Example usage:</p>
<pre name="code" class="css">// Example
body { color: red; }

// Generalization (not actual code)
body { color: color_name; }</pre>
<p>Because color names are easy to remember, they&#8217;re handy for getting quick results, especially while doing rapid prototyping.</p>
<p><a href="http://www.w3.org/TR/CSS1/#color-units">W3C&#8217;s CSS1 recommendation</a> first mentioned 16 color keywords that you can use: <em>aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow</em>:</p>
<table>
<tr>
<th>Color</th>
<th>Hexadecimal</th>
<th>Color</th>
<th>Hexadecimal</th>
<th>Color</th>
<th>Hexadecimal</th>
<th>Color</th>
<th>Hexadecimal</th>
</tr>
<tr>
<td>aqua / cyan</td>
<td style="background:#0FF; color:#000; font-family:monospace;">#00FFFF</td>
<td>gray</td>
<td style="background:#808080; color:#FFF; font-family:monospace;">#808080</td>
<td>navy</td>
<td style="background:#000080; color:#FFF; font-family:monospace;">#000080</td>
<td>silver</td>
<td style="background:#C0C0C0; color:#000; font-family:monospace;">#C0C0C0</td>
</tr>
<tr>
<td>black</td>
<td style="background:#000; color:#FFF; font-family:monospace;">#000000</td>
<td>green</td>
<td style="background:#008000; color:#FFF; font-family:monospace;">#008000</td>
<td>olive</td>
<td style="background:#808000; color:#FFF; font-family:monospace;">#808000</td>
<td>teal</td>
<td style="background:#008080; color:#fff; font-family:monospace;">#008080</td>
</tr>
<tr>
<td>blue</td>
<td style="background:#00F; color:#FFF; font-family:monospace;">#0000FF</td>
<td>lime</td>
<td style="background:#0F0; color:#000; font-family:monospace;">#00FF00</td>
<td>purple</td>
<td style="background:#800080; color:#FFF; font-family:monospace;">#800080</td>
<td>white</td>
<td style="background:#FFF; color:#000; font-family:monospace;">#FFFFFF</td>
</tr>
<tr>
<td>fuchsia / magenta</td>
<td style="background:#F0F; color:#000; font-family:monospace;">#FF00FF</td>
<td>maroon</td>
<td style="background:#800000; color:#FFF; font-family:monospace;">#800000</td>
<td>red</td>
<td style="background:#F00; color:#FFF; font-family:monospace;">#FF0000</td>
<td>yellow</td>
<td style="background:#FF0; color:#000; font-family:monospace;">#FFFF00</td>
</tr>
</table>
<p>(color table from <a href="http://en.wikipedia.org/wiki/Web_colors">Wikipedia</a>)</p>
<p><a href="http://www.w3.org/TR/CSS2/syndata.html#keywords">CSS2</a> officially mapped the colors to recommended hex values and also added the color orange.  <a href="http://www.w3.org/TR/css3-color/#html4">CSS3</a> removed orange, presumably because having 17 colors was aesthetically unpleasing in a binary world?</p>
<p>In addition to these 16 &#8220;official&#8221; colors, there&#8217;s <a href="http://www.w3schools.com/css/css_colornames.asp">even more unofficial color names</a> you can use that appear to be supported in all the major browsers.</p>
<h3>RGB values</h3>
<p>Example usage:</p>
<pre name="code" class="css">// Example
body { color: rgb(255,0,0); }

// Generalization (not actual code)
body { color: rgb(red [integer 0-255], green [integer 0-255], blue [integer 0-255]); }</pre>
<p>For this section it&#8217;s very handy to know a bit about <a href="http://en.wikipedia.org/wiki/Color_theory">color theory</a>, particularly these facts:</p>
<ul>
<li>all colors can be made from a combination of red, green, and blue (RGB) as the primary colors</li>
<li>in light (additive color mixing), the absence of all color results in the color black</li>
<li>in light (additive color mixing), the mixing of red, green, and blue in equal amounts results in the color white</li>
</ul>
<p>With the rgb attribute, we specify the amount of each color we want with an integer from 0 to 255.  Here we can see both black and white expressed as rgb values:</p>
<p>Black:<br />
<span class="small-box" style="background-color: rgb(0,0,0);"></span>rgb(0,0,0)</p>
<p>White:<br />
<span class="small-box" style="background-color: rgb(255,255,255);"></span>rgb(255,255,255)</p>
<p>Also note that if all three values are equal, there is no color that predominates and the result is a shade of gray.</p>
<p>Dark gray:</p>
<p><span class="small-box" style="background-color: rgb(30,30,30);"></span>rgb(30,30,30)</p>
<p>A lighter shade of gray:</p>
<p><span class="small-box" style="background-color: rgb(200,200,200);"></span>rgb(200,200,200)</p>
<p>And of course we can favor only one color, which in this case gives us a full red, with no green or blue:</p>
<p><span class="small-box" style="background-color: rgb(255,0,0);"></span>rgb(255,0,0)</p>
<p>You may have guessed that we can also use percentage values to represent the same color:</p>
<p><span class="small-box" style="background-color: rgb(100%, 0%, 0%);"></span>rgb(100%, 0%, 0%)</p>
<h3>RGBA values</h3>
<pre name="code" class="css">// Example
body { color: rgba(255,0,0,0.5); }

// Generalization (not actual code)
body { color: rgb(red [integer 0-255], green [integer 0-255], blue [integer 0-255], alpha transparency [float 0-1]); }</pre>
<p><a href="http://www.w3.org/TR/css3-color/#rgba-color">CSS3</a> introduced rgba, which is in every way similar to rgb, except for the addition of a fourth value, alpha opacity, which gives us control over the transparency of the color.</p>
<p>So the equivalent full red we have above would look like this (no transparency):</p>
<p><span class="small-box" style="background-color: rgba(255, 0, 0, 1);"></span>rgba(255, 0, 0, 1)</p>
<p><span class="small-box" style="background-color: rgba(100%, 0%, 0%, 1);"></span>rgba(100%, 0%, 0%, 1)</p>
<p>And the same color, only now semitransparent:</p>
<p><span class="small-box" style="background-color: rgba(255, 0, 0, 0.5);"></span>rgba(255, 0, 0, 0.5)</p>
<p><span class="small-box" style="background-color: rgba(100%, 0%, 0%, 0.5);"></span>rgba(100%, 0%, 0%, 0.5)</p>
<h3>Hex values</h3>
<p>Example usage:</p>
<pre name="code" class="css">// Example
body { color: #ff0000; }

// Generalization (not actual code)
body { color: #rrggbb; }</pre>
<p>Hex values are probably the most common out of all of the ways to represent colors in CSS.  But I included them last &#8211; what gives?  It seems to me that the rgb value should logically be explained first.  The hex value is just a hex version (and thus slightly more confusing version) of expressing rgb values.</p>
<p>For this section you ought to know the basics of <a href="http://en.wikipedia.org/wiki/Hexadecimal">hexadecimal numbers</a>.  In particular, the fact that hexadecimals are base 16 and use letters a-f to represent numbers beyond our conventional base 10 range.</p>
<p>The hex value starts with a hash (#) and is followed by six numbers and/or letters.  This is simply our three color values again: red, green, blue, with each color allowed two digits.</p>
<p>We express our solid red color like this:</p>
<p><span class="small-box" style="background-color: #ff0000;"></span>#ff0000</p>
<p>As long as you can convert between decimal and hexadecimal (there&#8217;s <a href="http://www.google.com/search?aq=f&#038;ie=UTF-8&#038;q=decimal+to+hex">a few free tools online</a>), it&#8217;s relatively easy to convert between rgb and hex color values.  Just keep in mind that the first 16 hex values are preceded by a zero (0 becomes 00, 1 becomes 01, 10 becomes 0a, 11 becomes 0b, etc.)</p>
<h3>Shorthand hex</h3>
<p>Example usage:</p>
<pre name="code" class="css">// Example
body { color: #f00; }

// Generalization (not actual code)
body { color: #rgb; }</pre>
<p>Last but not least, if each rgb value has a repeating value, you can simply omit the repeating value.  In the case above each of our color values was repeating (red = ff, green = 00, blue = 00), so we simply drop the repeating digit from each color and cut three bytes from our code:</p>
<p><span class="small-box" style="background-color: #f00;"></span>#f00</p>
<h3>A note on web-safe colors</h3>
<p><a href="http://en.wikipedia.org/wiki/Web_colors#Web-safe_colors">Web safe colors</a> were a recommended subset of about 256 colors with which to design websites.  The rationale for solely using them for web design was for rendering consistency, so even users with very limited displays could see the page as it was intended to be displayed.</p>
<p>The concept of a &#8220;web safe&#8221; color was becoming obsolete even in 1997 or so, when I started making my personal website on AOL.  It&#8217;s safe to say that the vast majority of users today are now able to view webpages with at least 16 million colors (256*256*256).</p>
<p>But this doesn&#8217;t mean we shouldn&#8217;t be concerned about colors.  Apart from pure aesthetics, in the area of accessibility it&#8217;s often mentioned that users with colorblindness find certain combinations of colors difficult to see.  So keep this in the back of your head when you go crazy with those wild color schemes!</p>
<h3>More info</h3>
<p>Probably the best way to learn how to use these color values is to actually try them on your website, however you might also find the following links useful.</p>
<div class="website"><a href="http://colorschemedesigner.com/"><img src="http://davidbcalhoun.com/wp-content/uploads/2009/12/color-scheme-designer.png" alt="Color Scheme Designer" title="Color Scheme Designer" width="300"/></a>
<div>
<p><a href="http://colorschemedesigner.com/">Color Scheme Designer</a> is a nice tool for finding several colors that (theoretically) should go well together.  It&#8217;s a nice place to go when building a website from the ground-up.</p>
<p><a href="http://colorschemedesigner.com/">http://colorschemedesigner.com/</a></p>
</div>
</div>
<div class="website"><a href="http://schlaeps.com/mootools/gradient-creator/"><img src="http://davidbcalhoun.com/wp-content/uploads/2009/12/mootols-webkit-gradient.png" alt="Color Scheme Designer" title="Color Scheme Designer" width="300"/></a>
<div>
<p><a href="http://schlaeps.com/mootools/gradient-creator/">Jonathan Schlaepfer</a> made a nice helper tool built in Mootols for creating webkit gradients.  Gradients wasn&#8217;t the subject of this entry, but it&#8217;s helpful to see a nice visualization of rgb values corresponding to the hex values.</p>
<p><a href="http://schlaeps.com/mootools/gradient-creator/">http://schlaeps.com/mootools/gradient-creator/</a></p>
</div>
</div>
<p><a href="http://en.wikipedia.org/wiki/Web_colors">Wikipedia: Web colors</a></p>
<p><a href="http://www.w3schools.com/html/html_colors.asp">HTML Colors</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/a-primer-on-css-colors/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Video: John Resig &#8211; Testing, Performance Analysis, and jQuery 1.4</title>
		<link>http://davidbcalhoun.com/2009/video-john-resig-testing-performance-analysis-and-jquery-1-4</link>
		<comments>http://davidbcalhoun.com/2009/video-john-resig-testing-performance-analysis-and-jquery-1-4#comments</comments>
		<pubDate>Tue, 22 Dec 2009 03:54:01 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[john resig]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=78</guid>
		<description><![CDATA[In case you hadn&#8217;t seen it yet, John Resig was kind enough to stop by Yahoo! for the December Bayjax meetup.  Here&#8217;s the video:

Usually developers are more interested in just getting the dang code to work, and as a result actual the testing and maintenance of JavaScript isn&#8217;t talked about too much, so I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>In case you hadn&#8217;t seen it yet, <a href="http://ejohn.org/">John Resig</a> was kind enough to stop by Yahoo! for the December <a href="http://www.meetup.com/BayJax/">Bayjax</a> meetup.  Here&#8217;s the <a href="http://developer.yahoo.com/yui/theater/video.php?v=resig-testing">video</a>:</p>
<div class="video" style="width:576px; height: 324px;"><object width="576" height="324"><param name="movie" value="http://d.yimg.com/m/up/ypp/default/player.swf"></param><param name="flashVars" value="vid=17156941&#038;"></param><param name="allowfullscreen" value="true"></param><param name="wmode" value="transparent"></param><embed width="576" height="324" allowFullScreen="true" src="http://d.yimg.com/m/up/ypp/default/player.swf" type="application/x-shockwave-flash" flashvars="vid=17156941&#038;"></embed></object></div>
<p>Usually developers are more interested in just getting the dang code to work, and as a result actual the testing and maintenance of JavaScript isn&#8217;t talked about too much, so I&#8217;m sure this will be new territory for many developers.  And since it&#8217;s John Resig speaking, there was of course a bit about using <a href="http://testswarm.com/">TestSwarm</a>, a testing distributed framework-agnostic automated testing tool (that&#8217;s a mouthful!).</p>
<p>Included in the talk are good things to note while testing, such as the fact unless you&#8217;re running Firefox or Chrome on Windows, all test times have a margin of error of up to 15ms (not to be confused with <a href="http://www.quirksmode.org/blog/archives/2009/08/when_to_read_ou.html">PPK&#8217;s observation of the delay between JavaScript computation and browser rendering</a>).</p>
<p>(via <a href="http://www.yuiblog.com/blog/2009/12/16/video-resig-testing-and-jquery/">YUIBlog</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/video-john-resig-testing-performance-analysis-and-jquery-1-4/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PastryKit: digging into an Apple Pie</title>
		<link>http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie</link>
		<comments>http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie#comments</comments>
		<pubDate>Wed, 16 Dec 2009 13:10:01 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[mobile]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[iui]]></category>
		<category><![CDATA[jqtouch]]></category>
		<category><![CDATA[pastrykit]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=66</guid>
		<description><![CDATA[Yesterday John Gruber wrote about Apple&#8217;s PastryKit, iPhone&#8217;s JavaScript framework that&#8217;s been discovered &#8220;in the wild&#8221; on the iPhone user guide at http://help.apple.com/iphone/3/mobile/.  There&#8217;s a few ways to access the page:

with an actual iPhone or iTouch
by browsing with an iPhone/iTouch user agent.  If you&#8217;re using Safari, enable the Developer menu in Safari&#62;Preferences&#62;Advanced and [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday <a href="http://daringfireball.net/2009/12/pastrykit">John Gruber wrote about Apple&#8217;s PastryKit</a>, iPhone&#8217;s JavaScript framework that&#8217;s been discovered &#8220;in the wild&#8221; on the iPhone user guide at <a href="http://help.apple.com/iphone/3/mobile/">http://help.apple.com/iphone/3/mobile/</a>.  There&#8217;s a few ways to access the page:</p>
<ul>
<li>with an actual iPhone or iTouch</li>
<li>by browsing with an iPhone/iTouch user agent.  If you&#8217;re using Safari, enable the Developer menu in Safari&gt;Preferences&gt;Advanced and switching user agents by clicking on Develope&gt;User Agent</li>
</ul>
<h3>What&#8217;s all the big fuss?</h3>
<p>John was particularly interested in the responsiveness and native-like interaction of flinging through long lists, the fact the address bar is completely hidden, and the possibility of having a toolbar fixed to the top of the page.  PastryKit makes all of these things possible and implements them better than anything else.  And the result is nearly indistinguishable from a native app.  Here&#8217;s a video I made of the iPhone user guide in action, powered by PastryKit.  This is running on Safari &#8211; it&#8217;s not a native app!</p>
<div style="align: center; margin: 1em auto; width: 640px;"><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/gV305XeIZyc&#038;hl=en_US&#038;fs=1&#038;color1=0x3a3a3a&#038;color2=0x999999"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/gV305XeIZyc&#038;hl=en_US&#038;fs=1&#038;color1=0x3a3a3a&#038;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></div>
<h3>PastryKit has been here for a while</h3>
<p>As John Gruber points out, the code for PastryKit has been there for quite a while now.  <a href="http://stackoverflow.com/questions/1143589/what-is-the-pastrykit-framework">Stack Overflow has a question about it</a> that was asked way back in July, and there are several more <a href="http://twitter.com/jQTouch/status/6146839190">recent references</a> to it by jQTouch developer David Kaneda on Twitter.  Of course, since John&#8217;s post there&#8217;s been an explosion of interest in the form of even more tweets!</p>
<p>Hopefully with all of this increased attention, we&#8217;ll see Apple take notice and address it.  Here&#8217;s hoping, anyway.</p>
<h3>Some interesting features</h3>
<p>There&#8217;s even more interesting takeaways from the PastryKit code, and I&#8217;m sure I&#8217;ve just barely scratched the surface:</p>
<ul>
<li>implements its own form of Object-Oriented programming (obj.inherits and obj.synthetizes properties).  When modules are declared, they&#8217;re registered as a PK Class (i.e. PKClass(PKBarButtonItem) registers PKBarButtonItem as a PK Class)</li>
<li>CSS3 wrapper functions (PKUtils.t() is a wrapper for translate3d, etc.)</li>
<li>no single library namespace (surprisingly) &#8211; which means there are many many global variables.  This however is somewhat acceptable, as all variables are prefixed with &#8220;PK&#8221; and are declared to be constant (const PKStartEvent, const PKEndEvent) and cannot be overwritten.</li>
</ul>
<p>There&#8217;s also some interesting takeaways not from PastryKit itself, but from the way the iPhone user guide is implemented.  Most of the data on the page &#8211; including each menu icon (base64 encoded) &#8211;  is located in a single 650kb JSON-encoded file called content.json.  This means the initial loading of the page is quite slower than the user would normally expect, but once the initial payload has been delivered, it&#8217;s a relatively smooth browsing experience thereafter.</p>
<p>And as John Gruber already pointed out, this data is stored locally with the help of HTML5, allowing the user to continue reading even while offline!</p>
<div id="attachment_75" class="wp-caption aligncenter" style="width: 329px"><img src="http://davidbcalhoun.com/wp-content/uploads/2009/12/apple-pastrykit.png" alt="iPhone user guide in Safari" title="iPhone user guide in Safari" width="319" height="480" class="size-full wp-image-75" /><p class="wp-caption-text">iPhone user guide in Safari</p></div>
<h3>PastryKit unminified and explained (sorta)</h3>
<p>What I&#8217;m excited to show you now is a result of a bit of effort to make PastryKit more intelligible.  Though there&#8217;s a <a href="http://help.apple.com/iphone/3/mobile/dist/PastryKit-ug-compact.js">minified version of the code</a> on Apple&#8217;s website, it&#8217;s not obfuscated (and rendered unintelligible), so not all hope is lost!  With the help of <a href="http://jsbeautifier.org/">jsbeautifier.org</a> we can now see the slightly unminified version of the code: <a href="http://davidbcalhoun.com/pastrykit/PastryKit.js">PastryKit.js unminified</a>.</p>
<p>The next thing I did was separate each module into its own file.  I was able to separate the code into 27 numbered files, with the original ordering preserved (to prevent issues with dependencies).  Viewing the code in this way definitely helps make sense of it all.  You can download these separate files as part of a little unofficial SDK I made, which also includes a copy of the iPhone user guide with the JS iPhone-only redirect removed: <a href="http://davidbcalhoun.com/pastrykit/pastrykit-sdk.zip">PastryKit unofficial SDK</a>.</p>
<h3>PastryKit modules</h3>
<p>The following is an explanation of each module I found.  The descriptions are definitely incomplete and possibly inaccurate, so any comments or help is appreciated.  But this should hopefully shed some light on the matter!</p>
<ul>
<li>PKUtils &#8211; general helper functions (PKUtils.t() is a wrapper for CSS translate3d, PKUtils.degreesToRadians(), etc, etc.)</li>
<li>PKEventTriage &#8211; general event handler</li>
<li>PKPropertyTriage &#8211; handlePropertyChange() method &#8211; ?</li>
<li>Element &#8211; helper functions added to HTML Element prototype</li>
<li>Node &#8211; adds getNearestView() method to HTML Node prototype</li>
<li>PKClass &#8211; custom-rolled class with with &#8220;inherits&#8221; and &#8220;synthetizes&#8221; properties</li>
<li>PKObject &#8211; custom-rolled object with observer pattern.  Most modules extend from this.</li>
<li>PKPoint &#8211; wrapper for WebKitPoint &#8211; used for touch events?</li>
<li>PKSize &#8211; wrapper for width/height properties</li>
<li>PKImage (inherits PKObject) &#8211; helper for creating Image elements and knowing when it&#8217;s finished loading (but doesn&#8217;t add the image to the DOM)</li>
<li>PKAnimator &#8211; basic animation tweens</li>
<li>PKTransition &#8211; helper for proprietary Webkit CSS transitions</li>
<li>PKTransaction &#8211; interacts with PKTransition &#8211; ?</li>
<li>PKView (extends PKObject) &#8211; manages a view, such as handling events that occur within that view &#8211; ?</li>
<li>PKContentView (extends PKView) &#8211; ?</li>
<li>PKRootView (extends PKContentView) &#8211; ?</li>
<li>PKScrollIndicator (extends PKView) &#8211; custom scrollbar</li>
<li>PKScrollView (extends PKView) &#8211; handles dynamically positioning the page when it&#8217;s scrolled</li>
<li>PKTableView (extends PKScrollView) &#8211; handles more touch/scroll events?</li>
<li>PKCellPath &#8211; ?</li>
<li>PKTableViewCell (extends PKView) &#8211; ?</li>
<li>PKToolbar (extends PKView) &#8211; manages the top toolbar</li>
<li>PKNavigationView (extends PKView) &#8211; manages bottom navigation bar</li>
<li>PKNavigationItem (extends PKObject) &#8211; manages bottom navigation buttons</li>
<li>PKControl (extends PKView) &#8211; manages generic controls</li>
<li>PKBarButtonItem (extends PKControl) &#8211; manages button controls</li>
<li>PKSearchBar.js (extends PKView) &#8211; manages the search bar</li>
</ul>
<h3>Conclusion after a first glance</h3>
<p>As far as I can tell, this is no full-fledged JavaScript library.  At least not for now.</p>
<p>On first glance PastryKit seems to be at most a nice development framework for making web apps with the same look-and-feel of native iPhone apps.  And this framework in many ways does this better than anything out there (at the moment).</p>
<p>I echo the sentiments of Gruber &#8211; I do hope we hear more about this from Apple!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/pastrykit-digging-into-an-apple-pie/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>JavaScript tidbit: special variables ($, $$, _, etc)</title>
		<link>http://davidbcalhoun.com/2009/javascript-tidbit-special-variables-_-etc</link>
		<comments>http://davidbcalhoun.com/2009/javascript-tidbit-special-variables-_-etc#comments</comments>
		<pubDate>Tue, 08 Dec 2009 11:24:54 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[$]]></category>
		<category><![CDATA[$$]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[_]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=61</guid>
		<description><![CDATA[You&#8217;re probably used to typical variables names such as the following:
var personName = 'Joe';
You may not realize it, but there are some non-alphanumeric variables at your disposal.
Using $
For instance, the $ variable has been made popular by several JavaScript libraries, most notably jQuery.  You can use it to alias operations that are commonly performed, [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;re probably used to typical variables names such as the following:</p>
<pre name="code" class="JScript">var personName = 'Joe';</pre>
<p>You may not realize it, but there are some non-alphanumeric variables at your disposal.</p>
<h3>Using $</h3>
<p>For instance, the $ variable has been made popular by several JavaScript libraries, most notably <a href="http://jquery.com/">jQuery</a>.  You can use it to alias operations that are commonly performed, such as the following (1):</p>
<pre name="code" class="JScript">var $ = document.getElementById;
var myElement = $('targetElement');</pre>
<p>If you declare this variable outside of a function it will be a global variable and will compete with libraries that use the same global variable, so it&#8217;s probably best not to use it.</p>
<p>Interestingly, originally the dollar sign $ was originally intended for &#8220;mechanically generated code&#8221; (2), but as the usage of the symbol has become popular for other purposes, it looks like <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm">the latest version of JavaScript (ECMAScript 5th edition) now officially &#8220;oks&#8221; its use</a>:</p>
<blockquote><p>This standard specifies specific character additions: The dollar sign ($) and the underscore (_) are permitted anywhere in an IdentifierName.</p></blockquote>
<h3>Using $$</h3>
<p>Some have come up with the solution of simply using two or more $$ symbols in order to distinguish the variable from libraries that just use a single $:</p>
<pre name="code" class="JScript">var $$ = document.getElementById;
var myElement = $$('targetElement');</pre>
<h3>Using _</h3>
<p>You will find that you can use the underscore _ in the same way to alias variables and functions:</p>
<pre name="code" class="JScript">var _ = document.getElementById;
var myElement = _('targetElement');</pre>
<h3>Other symbols</h3>
<p>If you&#8217;re really getting adventurous, you can even try using other symbols such as square root √, which seems to work just fine, just as $ and _ above.  The only problem: it&#8217;s quite inconvenient using it, since it&#8217;s not available on any keyboards (except through some crazy key combinations perhaps).</p>
<p>Or you can put the symbol to use doing what you would naturally think it should do&#8230;</p>
<pre name="code" class="JScript">var √ = Math.sqrt;
alert(√(4));   // 2</pre>
<h3>References</h3>
<p>(1) <a href="http://www.amazon.com/Even-Faster-Web-Sites-Performance/dp/0596522304">Even Faster Web Sites</a>, p. 128<br />
(2) <a href="http://stackoverflow.com/questions/205853/why-would-a-javascript-variable-start-with-a-dollar-sign">Stackoverflow: Why would a javascript variable start with a dollar sign?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/javascript-tidbit-special-variables-_-etc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ways of passing data to functions in JavaScript</title>
		<link>http://davidbcalhoun.com/2009/passing-data-to-functions-in-javascript</link>
		<comments>http://davidbcalhoun.com/2009/passing-data-to-functions-in-javascript#comments</comments>
		<pubDate>Sat, 05 Dec 2009 03:41:48 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[functions]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=51</guid>
		<description><![CDATA[Passing data is quite important in functional programming languages like JavaScript.  When there are multiple functions (which is most of the time), there needs to be a way to pass data between the functions.  This is done by passing values in parenthesis: myFunction(myData).  Even when there is no data to be passed, [...]]]></description>
			<content:encoded><![CDATA[<p>Passing data is quite important in functional programming languages like JavaScript.  When there are multiple functions (which is most of the time), there needs to be a way to pass data between the functions.  This is done by passing values in parenthesis: myFunction(myData).  Even when there is no data to be passed, we still have to declare and execute functions by using parenthesis: myFunction().</p>
<h3>Simple Passing</h3>
<p>I&#8217;ve already referred to the common method of passing data.  Here&#8217;s an example of the code in action:</p>
<pre name="code" class="JScript">function greeting (name) {
    alert('Hello ' + name);
}
var personsName = 'Joe';
greeting(personsName);  // Hello Joe</pre>
<p>This example only passes one variable to the function.  Note that we can get rid of the variable personsName and make the string on the fly.  So the code above is equivalent to this:</p>
<pre name="code" class="JScript">function greeting (name) {
    alert('Hello ' + name);
}
greeting('Joe');  // Hello Joe</pre>
<p>Ok.  Now let&#8217;s suppose we have a function that accepts two variables:</p>
<pre name="code" class="JScript">function greeting (firstName, lastName) {
    alert('Hello ' + firstName + ' ' + lastName);
}
greeting('Joe', 'Schmoe');  // Hello Joe Schmoe</pre>
<p>This doesn&#8217;t look too hard.  But there&#8217;s a catch &#8211; the person writing the code has to remember the order of variables to pass in.  Suppose they call the function like this:</p>
<pre name="code" class="JScript">function greeting (firstName, lastName) {
    alert('Hello ' + firstName + ' ' + lastName);
}
greeting('Schmoe', 'Joe');  // Hello Schmoe Joe</pre>
<p>That&#8217;s no good!  This isn&#8217;t the result we want.  In the case of firstName and lastName the variable order isn&#8217;t too hard to remember, but in other cases the variables aren&#8217;t in any logical order, which can cause confusion.</p>
<h3>No constructor overloading</h3>
<p>Unlike other languages such as C++ and Java, JavaScript has no <a href="http://en.wikipedia.org/wiki/Method_overloading">constructor overloading</a>.  In fact, JavaScript is (for better or worse) not even strict about enforcing the number of variables passed in.  For example, the following code works fine and throws no errors, even though we&#8217;re not passing in a variable in the function call:</p>
<pre name="code" class="JScript">function test (someVar) {
    // do stuff
};
test();  // no errors!</pre>
<p>It&#8217;s only when you try to use someVar within the function that causes the problems.  Otherwise, everything&#8217;s working just fine and dandy.</p>
<p>What happens if we try the other case scenario: pass in more variables than the function expects?  No errors again:</p>
<pre name="code" class="JScript">function test () {
    // do stuff
};
test('testing 123');  // again, no errors</pre>
<p>And what happens if we try to declare a function with the same name?  No errors, but the previous function is overwritten (this is generally to be avoided of course):</p>
<pre name="code" class="JScript">function test () {
    alert('First function');
};
function test () {
    alert('Second function');
};
test();  // Second function</pre>
<p>Because JavaScript has no function overloading, all it takes to overwrite another function is to redeclare a function with the same name.  It doesn&#8217;t matter what sort of arguments they accept.</p>
<h3>Passing with the help of the arguments object</h3>
<p>As it turns out, JavaScript has a handy arguments object to access the arguments passed into each function:</p>
<pre name="code" class="JScript">function test () {
    alert(arguments[0]);    // testing 123
};
test('testing 123');</pre>
<p>In the above case the arguments object acts just as an array &#8211; it&#8217;s 0-indexed and can be used to access any arbitrary number of arguments.  But arguments also has an interesting and useful property: length.  Using arguments.length, we can traverse the array of arguments.  This is handy in cases where we might want to add an arbitrary number of elements together:</p>
<pre name="code" class="JScript">function add () {
    var sumTotal = 0;                        // initialize total to 0

    for(var i=0; i&lt;arguments.length; i++) {  // for each argument
        sumTotal += arguments[i];            // add current argument to total
    }

    alert(sumTotal);
};
add(2, 3, 4);  // 9
add(1, 1, 1, 1, 1, 1, 1, 1, 1);  // 9
</pre>
<h3>Passing an object</h3>
<p>JavaScript libraries such as <a href="http://developer.yahoo.com/yui/">YUI</a> have already learned that the variable order is a common nuisance and an opportunity to introduce errors, so they&#8217;ve come up with a solution: pass a single object to the function.  It ends up looking something like this:</p>
<pre name="code" class="JScript">function greeting (obj) {
    alert('Hello ' + obj.first + ' ' + obj.last);
}
var nameObject = {};
nameObject.first = 'Joe';
nameObject.last = 'Schmoe';
greeting(nameObject);  // Hello Joe Schmoe</pre>
<p>Now the variables become properties of a single object which is passed into the function.  And it doesn&#8217;t matter which order the properties are declared in, which is a great relief to the developer.</p>
<p>Note that we can simplify the above code:</p>
<pre name="code" class="JScript">function greeting (obj) {
    alert('Hello ' + obj.first + ' ' + obj.last);
}
var nameObject = {
    first: 'Joe',
    last: 'Schmoe'
};
greeting(nameObject);  // Hello Joe Schmoe</pre>
<p>And we can simplify even further:</p>
<pre name="code" class="JScript">function greeting (obj) {
    alert('Hello ' + obj.first + ' ' + obj.last);
}
greeting({
    first: 'Joe',
    last: 'Schmoe'
});  // Hello Joe Schmoe</pre>
<p>This is the form commonly used in these JavaScript libraries.  It&#8217;s easy to copy-and-paste example code, but it might not always be so obvious what&#8217;s going on behind the scenes.  You can see that just as we bypassed declaring a named variable in the Simple Passing model (with greeting(&#8221;)), here we use the same shortcut and bypass declaring a named object (with greeting({})).</p>
<h3>call() and apply()</h3>
<p>These two methods have different techniques for passing data to functions, but I&#8217;m going to have to hold off on them for now.  It&#8217;s a bit complicated, since they&#8217;re only used to execute methods (functions) in other object contexts.  But seeing as I need to explain object context to get into that, I&#8217;ll save that for a future entry!</p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/passing-data-to-functions-in-javascript/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
