<?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>Jason Rowe &#187; JavaScript</title>
	<atom:link href="http://jasonrowe.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://jasonrowe.com</link>
	<description>enjoying the web</description>
	<lastBuildDate>Tue, 03 Jan 2012 02:03:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Getting back into JavaScript</title>
		<link>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-back-into-javascript</link>
		<comments>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 04:17:32 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[General Programming]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[charting]]></category>

		<guid isPermaLink="false">http://jasonrowe.com/?p=1498</guid>
		<description><![CDATA[The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts. Note: Here is a quick overview of JavaScript that is as short&#8230;]]></description>
			<content:encoded><![CDATA[<p>The last time I did any serious JavaScript was around the time Sizzle was added to JQuery, Google Chrome was brand new, and MarketWatch.com started using canvas charts.</p> 

<p><strong>Note:</strong> Here is a quick <a href="http://www.2ality.com/2011/10/javascript-overview.html">overview of JavaScript</a> that is as short as possible, but explains every major feature. I would also recommend following the <a href="http://www.2ality.com/">2ality</a> website</p>

<p>Today JavaScript projects have the complexity, size, and structure of projects written in languages like C# and Java. Thankfully, the developer tools for debugging and logging are solid across browsers. *<i>Opera is still a little funky about logging using &#8220;opera.postError.apply(opera, arguments);&#8221;</i>. Looking particularly good, <a href="http://code.google.com/chrome/devtools/">Google&#8217;s version of the webkit dev tools</a> and some API&#8217;s they have in <a href="http://code.google.com/chrome/extensions/dev/experimental.devtools.html">beta</a>. I’ve started to use <a href="http://docs.jquery.com/QUnit">quint</a> for unit testing. I’ve also been looking leveraging these frameworks: <a href="http://documentcloud.github.com/underscore/">underscore.js</a>, <a href="http://jashkenas.github.com/coffee-script/">coffee script</a>, <a href="http://raphaeljs.com/">raphaeljs</a>, and <a href="http://code.google.com/closure/compiler/">closure compiler</a>.</p> <p>It’s amazing how much has changed. Now <a href="https://developer.mozilla.org/en/JavaScript/Reference">examples of good JavaScript</a> are much easier to find. Hell, here is a step by step walkthrough of how to <a href="http://dailyjs.com/tags.html#lmaf">build your very own JavaScript framework</a>.</p> 

<p>So to get some practice I went and found some JS that needed cleanup. I wanted to focus on structure and namespaces and this <a href="http://www.elated.com/res/File/articles/development/javascript/snazzy-animated-pie-chart-html5-jquery/">script</a> needed some love. View source on that page and you will notice global variables and one big pile of code.</p> <p>The first thing I did was break up the logic into separate functional script files that will later be compiled and minified into one. You can see the python script I use to minify <a href="https://raw.github.com/JasonRowe/SimpleHTML5.Charts/master/build.py">here</a>.</p> 

<ol> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/animation.js">animation.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/builder.js">builder.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/core.js">core.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/pie.js">pie.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/rendering.js">rendering.js</a></li> 
<li><a href="https://github.com/JasonRowe/SimpleHTML5.Charts/blob/master/src/styles.js">styles.js</a></li>
</ol> 

<p>I then added a <a href="https://github.com/JasonRowe/SimpleHTML5.Charts/tree/master/test">test folder</a> and setup the same file names but which had test cases for each script. Then an index.html file to display the test groups or “modules” as they are called in QUnit. Here is an example of a test that always passes</p> 

<pre class="brush: js; ">

module(&quot;sample test&quot;);

test(&quot;a sample qunit test&quot;, function () {
    ok(true, &quot;always fine&quot;);
});


</pre>  

<p>The next thing I worked on was getting a namespace around the code. I went with the following which seems to work for my needs.</p> 

<pre class="brush: js; ">

var MYAPP = MYAPP || {};

MYAPP.namespace = function (ns_string) { var parts = ns_string.split(&#039;.&#039;), parent = MYAPP, i; // strip redundant leading global 

if (parts[0] === &quot;MYAPP&quot;) { parts = parts.slice(1); } for (i = 0; i &lt; parts.length; i += 1) { // create a property if it doesn&#039;t exist 

if (typeof parent[parts[i]] === &quot;undefined&quot;) { parent[parts[i]] = {}; 

} parent = parent[parts[i]]; } return parent; }; 


</pre>  

<p>Stefanov, Stoyan (2010). JavaScript Patterns (pp. 89-90). OReilly Media &#8211; A. Kindle Edition. </p>

<p>So after refactoring, I’ve got the pie chart setup code to the following.</p>

<pre class="brush: js; ">

var pieElm = document.getElementById(&#039;pieChart&#039;);
var pieData = $(&#039;#chartData td&#039;);

var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData);

$(&#039;#pieChart&#039;).click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);

</pre>

<p>To customize the style I allow passing in a custom style object to override the defaults.</p>

<pre class="brush: js; ">


var customStyles = {
    chartSizePercent: 49,
    maxPullOutDistance: 10,
    pullOutFrameStep: 4,
    pullOutFrameInterval: 40,
    pullOutLabelPadding: 42
};

var pieElm = document.getElementById(&#039;pieChart&#039;);
var pieData = $(&#039;#chartData td&#039;);
var pieChart = new SimpleHtml5.Core.Pie(pieElm, pieData, customStyles);
$(&#039;#pieChart&#039;).click (pieChart, SimpleHtml5.Pie.Animation.HandleChartClick);

</pre>

<p>
If you are curious about how the other parts of the chart were organized you can see the source code on <a href="https://github.com/JasonRowe/SimpleHTML5.Charts">github</a>.
</p>

<p>

<blockquote>I can also be found on Google+

<a title="Jason Rowe is on Google+" rel="author" href="http://profiles.google.com/jasonrowe?rel=author" alt="Google+" title="Google+">Jason Rowe</a> and twitter <a title="Jason Rowe is on twitter" rel="author" href="http://twitter.com/jsonrow?rel=author" alt="twitter" title="twitter">@jsonrow</a>
</blockquote>


</p>

]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2011/11/02/getting-back-into-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Carousel Control CD Collection</title>
		<link>http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=carousel-control-cd-collection</link>
		<comments>http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 05:29:00 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=96</guid>
		<description><![CDATA[I wanted to find an easy way to display a CD collection using javascript instead of flash. While looking around I found a YUI extension called carousel. Here is my small static example of a CD collection. Bill Scott actually&#8230;]]></description>
			<content:encoded><![CDATA[<a href="http://rowejason.com/search"><img style="float: left; margin: 0px 10px 10px 0px; cursor: hand" src="http://www.rowejason.com/uploaded_images/carousel_example-779114.JPG" border="0" alt="snapshot of carousel" /></a> I wanted to find an easy way to display a CD collection using javascript instead of flash. While looking around I found a YUI extension called carousel. Here is my small static example of a CD collection.

Bill Scott actually doesn&#8217;t support this anymore and the YUI team has taken this on. The new version is very clean and I did try it out. I converted my carousel to the new YUI version but later decided to go with a JQuery extention called jCarousel. They both worked but I think I am going to move in the Jquery direction for awhile.
<a href="http://jasonrowe.com/search"> http://jasonrowe.com/search</a>

References:
<a href="http://billwscott.com/carousel/">http://billwscott.com/carousel/</a>

<a href="http://sorgalla.com/projects/jcarousel/">http://sorgalla.com/projects/jcarousel/</a>

<a href="http://developer.yahoo.com/yui/carousel/">http://developer.yahoo.com/yui/carousel/</a>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2007/07/18/carousel-control-cd-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript: Create Advanced Web Applications With Object-Oriented Techniques</title>
		<link>http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=javascript-create-advanced-web-applications-with-object-oriented-techniques</link>
		<comments>http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/#comments</comments>
		<pubDate>Mon, 07 May 2007 15:47:00 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://rowejason.com/?p=83</guid>
		<description><![CDATA[I just started working with OOP in javascript and found this article very informative. The section on prototypes was very helpful as I have been digging around in the YUI library lately and found that area confusing. JavaScript: Create Advanced&#8230;]]></description>
			<content:encoded><![CDATA[I just started working with OOP in javascript and found this article very informative. The section on prototypes was very helpful as I have been digging around in the YUI library lately and found that area confusing. <a href="http://msdn.microsoft.com/msdnmag/issues/07/05/javascript/default.aspx">JavaScript: Create Advanced Web Applications With Object-Oriented Techniques</a>

The article has lots of examples if you click on the figure links. Here was a useful one on Inheriting from a Prototype:

<code>
Inheriting from a Prototypefunction GreatDane() { }
var rover = new GreatDane();
var spot = new GreatDane();
GreatDane.prototype.getBreed = function() {
return “Great Dane”;
};</code><code>// Works, even though at this point
// rover and spot are already created.
alert(rover.getBreed());
// this hides getBreed() in GreatDane.prototype
spot.getBreed = function() {
return “Little Great Dane”;
};
alert(spot.getBreed());
// but of course, the change to getBreed
// doesn’t propagate back to GreatDane.prototype
// and other objects inheriting from it,
// it only happens in the spot object
alert(rover.getBreed());

</code>]]></content:encoded>
			<wfw:commentRss>http://jasonrowe.com/2007/05/07/javascript-create-advanced-web-applications-with-object-oriented-techniques/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

