<?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>Nick Zalabak - techwhizbang &#187; javascript</title>
	<atom:link href="http://techwhizbang.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://techwhizbang.com</link>
	<description>my work, life, and ideas</description>
	<lastBuildDate>Wed, 25 Jan 2012 05:47:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Object Oriented JavaScript</title>
		<link>http://techwhizbang.com/2011/05/object-oriented-javascript/</link>
		<comments>http://techwhizbang.com/2011/05/object-oriented-javascript/#comments</comments>
		<pubDate>Wed, 11 May 2011 07:10:39 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[object oriented]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=428</guid>
		<description><![CDATA[This is a presentation I gave recently on Object Oriented JavaScript. There is also source code that goes along with it that can be found here: https://github.com/techwhizbang/js_techtalk Object Oriented JavaScript View more presentations from techwhizbang]]></description>
			<content:encoded><![CDATA[<p>This is a presentation I gave recently on Object Oriented JavaScript. There is also source code that goes along with it that can be found here: <a href="https://github.com/techwhizbang/js_techtalk">https://github.com/techwhizbang/js_techtalk</a></p>
<div style="width:425px" id="__ss_7919789"> <strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/techwhizbang/object-oriented-javascript-7919789" title="Object Oriented JavaScript">Object Oriented JavaScript</a></strong> <iframe src="http://www.slideshare.net/slideshow/embed_code/7919789" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<div style="padding:5px 0 12px"> View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/techwhizbang">techwhizbang</a> </div>
</p></div>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2011/05/object-oriented-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript MVC Pattern</title>
		<link>http://techwhizbang.com/2011/04/javascript-mvc-pattern/</link>
		<comments>http://techwhizbang.com/2011/04/javascript-mvc-pattern/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 21:46:06 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=395</guid>
		<description><![CDATA[There are a lot of excellent JavaScript frameworks to choose from that provide some sort of MVC pattern. Of the most popular frameworks under this broad umbrella include Backbone.js, Sencha ExtJS, and SproutCore. All of these frameworks have their strengths, but I really crave simplicity. I really don&#8217;t want to have to read about a [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of excellent JavaScript frameworks to choose from that provide some sort of MVC pattern. Of the most popular frameworks under this broad umbrella include Backbone.js, Sencha ExtJS, and SproutCore. All of these frameworks have their strengths, but I really crave simplicity. I really don&#8217;t want to have to read about a framework for a couple hours and fiddle with it before I become productive. I really don&#8217;t want to scrap all of the &#8220;legacy&#8221; JavaScript written and attempt to shoehorn the framework into my project. I really don&#8217;t need all those super fancy UI widgets. You might be thinking the same thing, but you recognize that the way you&#8217;ve been organizing and/or writing JavaScript is flawed. The biggest mistake I see again and again is that the patterns we adhere to when writing in our favorite server side language are thrown to the wind when using JavaScript. Why? Why? Why? I could speculate and throw my theories out there, but none of that really matters. The thing that matters most is that you have recognized that something is wrong and you&#8217;d like to correct it.</p>
<p>I&#8217;d like to offer up a pattern I follow when writing JavaScript.<br />
Let&#8217;s take a look at the JavaScript MVC pattern I follow.</p>
<p>First things first. In your JavaScript directory, create the following folders.</p>
<ul>
<li>controllers</li>
<li>models</li>
<li>views</li>
<li>handlers</li>
<li>pages</li>
</ul>
<p>Handlers? Pages? What? No worries. I will discuss each of these and of course you can fit and mold this pattern to your needs. My examples assume you&#8217;re using <a href="http://jquery.com/" target="_blank">jQuery</a>, but you could use <a href="http://mootools.net/" target="_blank">MooTools</a>, <a href="http://www.prototypejs.org/" target="_blank">prototype</a>, or none of them.</p>
<h3>Models:</h3>
<p>As an example lets say you have some data that represents <em>projects</em>. Create a file under your models directory called <em>project.js</em>. I like to do &#8220;Object-Oriented&#8221; JavaScript so maybe your project.js would look like this.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Project <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>projectId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">projectId</span> <span style="color: #339933;">=</span> projectId<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
Project.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">find</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>projectId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'projects/'</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">projectId</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.json'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//do whatever with your data</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I&#8217;d also like to point out that I often like to write the JSON or XML I need (when I can) to the page so that I don&#8217;t make superfluous network calls. In this example I created a function called <em>find</em> that makes an Ajax call, but it could be just as simple to read JSON from a hidden element with a custom attribute called &#8220;data&#8221; on it like so.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
* Reads JSON from a hidden element on the page with an attribute called 'data'
* Example: &lt;input type=&quot;hidden&quot; /&gt;
*/</span>
&nbsp;
Project.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">all</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>dataSelector<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> $.<span style="color: #660066;">parseJSON</span><span style="color: #009900;">&#40;</span>dataSelector.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>My philosophy on JavaScript models is to keep them centered on the retrieval of the data they represent. Nothing more, nothing less.</p>
<h3>Views:</h3>
<p>This is the area where I feel most people go wrong and is generally my biggest gripe. How many times have you cracked open a .js file and found N-instances of the selector flying all over the code. Let me clarify. For example, you have a project carousel widget on your site and the selector has an id, namely <em>projects</em>. So everywhere, you look</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;">'#projects'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">something</span></pre></div></div>

<p>is recklessly abundant all throughout the code. Good luck re-factoring or repurposing that, even _with_ tests, especially after a few months.</p>
<p>Now, had you captured all the selectors for your <em>projects</em> view in a file managed under the views directory and properly added a layer of encapsulation. It would have taken you 2 seconds to swap whatever existing selectors there were with a new one or perhaps extended your projects view. Sometimes I like to use a view factory to encapsulate my views. Again, you don&#8217;t have to use the factory pattern you could just run the prototype pattern directly. Here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">ProjectViewFactory <span style="color: #339933;">=</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>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> BaseProjectView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;baseProjectView&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  BaseProjectView.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getProjectDataSelector</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#projects'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> CarouselProjectView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;carouselProjectView&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #006600; font-style: italic;">//I hand rolled a simple inheritance mechanism, you can find it under my Github account as inheritance.js</span>
  CarouselProjectView.<span style="color: #660066;">inheritsFrom</span><span style="color: #009900;">&#40;</span>BaseProjectView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  CarouselProjectView.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getProjectDataSelector</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#carouselProjects'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  CarouselProjectView.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getNextSelector</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getProjectDataSelector</span>.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.next'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  CarouselProjectView.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">getPreviousSelector</span> <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getProjectDataSelector</span>.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.previous'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
    getCarouselProjectView<span style="color: #339933;">:</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: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> CarouselProjectView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The fundamental concept is to align your view widgets on a page to a file managed under the views directory. Anytime, you use a selector it better be in a file like this. Never leak a selector outside the views directory. It is a very simple and straightforward rule to remember.</p>
<h3>Controllers:</h3>
<p>I like to keep my controllers slim and trim akin to the principle used very often in the Rails community.<br />
Your controllers should be passed the appropriate views required to activate and listen for the appropriate binding events (ie click, mouseover, etc). The controller should only bind the events and then hand the rest of the actual duties off to what I call a <i>handler</i> (we&#8217;ll discuss handlers next). Here is an example:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">ProjectsController <span style="color: #339933;">=</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>
&nbsp;
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   bindEvents <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>projectsView<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #003366; font-weight: bold;">var</span> projectModel <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Project<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> projectHandler <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ProjectHandler<span style="color: #009900;">&#40;</span>projectsView<span style="color: #339933;">,</span> projectModel<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     projectsView.<span style="color: #660066;">getNextSelector</span>.<span style="color: #660066;">click</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>
       projectHandler.<span style="color: #660066;">updateToNext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     projects.<span style="color: #660066;">getPreviousSelector</span>.<span style="color: #660066;">click</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>
       projectHandler.<span style="color: #660066;">updateToPrevious</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Handlers:</h3>
<p>I&#8217;d like to introduce one more letter in the MVC acronym, &#8220;H&#8221;. A handler is in charge of the dirty work bound to the event triggered. So you can imagine that with a project carousel with a next and previous button that several different things might happen like an image transition, description, numbering, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">ProjectHandler <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>projectView<span style="color: #339933;">,</span> projectModel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">projectView</span> <span style="color: #339933;">=</span> projectView<span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">projectModel</span> <span style="color: #339933;">=</span> projectModel<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
ProjectHandler.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">updateToPrevious</span> <span style="color: #339933;">=</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;">// fill in the details here</span>
<span style="color: #009900;">&#125;</span>
ProjectHandler.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">updateToNext</span> <span style="color: #339933;">=</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;">// fill in the details here</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h3>Pages:</h3>
<p>The last and final piece of the puzzle. So a page may consist of many different things including a project carousel, recommendations, comments, and whatever else you can dream up. Assuming you followed the rules given above that means you&#8217;ve developed a projects, recommendations, and comments controller along with their corresponding views, models, and handlers.<br />
So a <i>page</i> might look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">SomeAwesomePage <span style="color: #339933;">=</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: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
    bindEvents<span style="color: #339933;">:</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;">//initialize the views needed here</span>
      ProjectsController.<span style="color: #660066;">bindEvents</span><span style="color: #009900;">&#40;</span>projectsView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      RecommendationsController.<span style="color: #660066;">bindEvents</span><span style="color: #009900;">&#40;</span>recommendationsView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      CommentsController.<span style="color: #660066;">bindEvents</span><span style="color: #009900;">&#40;</span>commentsView<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Following this pattern lends itself to a very flexible and modular design. It is totally agnostic to other frameworks that you might already be using. The beauty part of this approach is that you can take a pure JavaScript approach without the bulkiness or dependency on yet another pre-defined framework and spin it to the needs of your project. I always encourage testing JavaScript. Recently I&#8217;ve been pairing this pattern with Jasmine.</p>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2011/04/javascript-mvc-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Testing with Jasmine</title>
		<link>http://techwhizbang.com/2011/02/javascript-testing-with-jasmine/</link>
		<comments>http://techwhizbang.com/2011/02/javascript-testing-with-jasmine/#comments</comments>
		<pubDate>Thu, 24 Feb 2011 01:35:51 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[jasmine]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=385</guid>
		<description><![CDATA[This is a presentation I gave on the use of Jasmine, a BDD testing framework for JavaScript. Examples of Jasmine specs can be found here: https://github.com/techwhizbang/js_techtalk. Have a look at my presentation on Object Oriented JavaScript also. Testing JavaScript with Jasmine View more presentations from techwhizbang.]]></description>
			<content:encoded><![CDATA[<p>This is a presentation I gave on the use of Jasmine, a BDD testing framework for JavaScript. Examples of Jasmine specs can be found here: <a href="https://github.com/techwhizbang/js_techtalk">https://github.com/techwhizbang/js_techtalk</a>.<br />
Have a look at my presentation on <a href="http://techwhizbang.com/2011/05/object-oriented-javascript/">Object Oriented JavaScript</a> also.</p>
<div style="width:425px" id="__ss_7037839"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/techwhizbang/testing-javascript-with-jasmine" title="Testing JavaScript with Jasmine">Testing JavaScript with Jasmine</a></strong><object id="__sse7037839" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=unittestingjavascript-110223193423-phpapp02&#038;stripped_title=testing-javascript-with-jasmine&#038;userName=techwhizbang" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed name="__sse7037839" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=unittestingjavascript-110223193423-phpapp02&#038;stripped_title=testing-javascript-with-jasmine&#038;userName=techwhizbang" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/techwhizbang">techwhizbang</a>.</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2011/02/javascript-testing-with-jasmine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started With Processing.js Tutorial</title>
		<link>http://techwhizbang.com/2010/03/processingjs-tutorial/</link>
		<comments>http://techwhizbang.com/2010/03/processingjs-tutorial/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 19:56:04 +0000</pubDate>
		<dc:creator>techwhizbang</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[data visualization]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[processing.js]]></category>

		<guid isPermaLink="false">http://techwhizbang.com/?p=99</guid>
		<description><![CDATA[This past week I&#8217;ve had the opportunity to really dig in and give processing.js a work out. For those not familiar with the technology, processing.js is a JavaScript library based on the Java based processing library available for download at http://dev.processing.org/. Processing.js uses the HTML5 Canvas element to draw shapes and designs while using a [...]]]></description>
			<content:encoded><![CDATA[<p><img class=" alignnone" title="Processing.js image" src="http://processingjs.org/content/download/processingjs.gif" alt="Processing.js" width="48" height="48" />This past week I&#8217;ve had the opportunity to really dig in and give <a href="http://processingjs.org" target="_blank">processing.js</a> a work out. For those not familiar with the technology, processing.js is a JavaScript library based on the Java based processing library available for download at <a href="http://dev.processing.org/" target="_blank">http://dev.processing.org/</a>. Processing.js uses the HTML5 Canvas element to draw shapes and designs while using a similar API to the one defined by the Java library.</p>
<p>I found the barrier to entry was unnecessarily frustrating due to the lack of a _good_ beginners tutorial calling out common pitfalls. But don&#8217;t let this sway you, because once you move past this, it is really fun.</p>
<p>Here are the things they don&#8217;t tell you about getting started.</p>
<ul></ul>
<ol>
<li>You should download the <a href="http://processingjs.org/content/download/processing-js-0.6-examples.zip" target="_blank">basic examples zip</a> from the their site.</li>
<li>You&#8217;ll want to grab the processing.init.js and the processing.js from the zip or tarball to include on your page.</li>
<li>As you begin coding you must tag any processing.js script on your page with

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span>“application<span style="color: #339933;">/</span>processing”<span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//your script here</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

</li>
<li>You must have a corresponding

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>canvas width<span style="color: #339933;">=</span>“200px” height<span style="color: #339933;">=</span>“200px”<span style="color: #339933;">&gt;&lt;/</span>canvas<span style="color: #339933;">&gt;</span></pre></div></div>

<p>         tag after your script in order for it to render the drawing. Make height and width whatever size you&#8217;d like.</li>
<li>Another note is that you can have multiple canvases on your page, you&#8217;re not limited to one.</li>
<li>The processing.init.js looks for

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span>“application<span style="color: #339933;">/</span>processing”<span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>            tag on your page and performs the processing.js initialization, if you don&#8217;t have this included on your page nothing will be drawn.</li>
<li>An alternative to using the processing.init.js and &lt;script type=&#8221;application/processing&#8221;&gt;&lt;/script&gt; is to use the datasrc attribute on the canvas tag.

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>canvas datasrc<span style="color: #339933;">=</span>”your_processing_script.<span style="color: #660066;">js</span>”<span style="color: #339933;">&gt;&lt;/</span>canvas<span style="color: #339933;">&gt;</span></pre></div></div>

</li>
</ol>
<p>These are just some of the things I ran into and I hope this helps anyone trying to get started with processsing.js. Next time I will post something using the processing.js library.</p>
<ul></ul>
]]></content:encoded>
			<wfw:commentRss>http://techwhizbang.com/2010/03/processingjs-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.731 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-06 14:50:48 -->

