<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" gd:etag="W/&quot;D0IMQXs-fSp7ImA9WhFSFUs.&quot;"><id>tag:blogger.com,1999:blog-30404818</id><updated>2013-06-18T09:26:20.555-05:00</updated><category term="Random" /><category term="Visual Studio" /><category term="Book Review" /><category term="Twitter" /><category term="Riddle" /><category term="Joke" /><category term="jQuery" /><category term="CSS" /><category term="Amplify" /><category term="Regular Expressions" /><category term="Podcast" /><category term="Sublime Text 2" /><category term="Cheat Sheet" /><category term="Screencast" /><category term="Find the jQuery Bug" /><category term="MVC Contrib" /><category term="jQuery Mobile" /><category term="Extensions" /><category term="jQuery UI" /><category term="Pluralsight" /><category term="Interview" /><category term="ASP.NET MVC" /><category term="CouchDB" /><category term="ASP.NET" /><category term="Quote" /><category term="Browser" /><category term="CoffeeScript" /><category term="Firefox" /><category term="Firebug" /><category term="Tip" /><category term="NuGet" /><category term="CSS3" /><category term="Angry Birds of JavaScript" /><category term="Backbone" /><category term="Conference" /><category term="AmplifyJS" /><category term="Tools" /><category term="Humor" /><category term="Internet Explorer" /><category term="Twitter Bootstrap" /><category term="Giveaway" /><category term="JavaScript" /><category term="Health" /><category term="Unit Testing" /><category term="HTML5" /><category term=".NET" /><title>Web Dev .NET</title><subtitle type="html">Front-end Web Dev Tips, Tricks, and Tools</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>529</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/webdevnet" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="webdevnet" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry gd:etag="W/&quot;AkAMQXw5eCp7ImA9WhFTE0g.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-3102607897877275476</id><published>2013-06-04T09:42:00.001-05:00</published><updated>2013-06-04T10:13:00.220-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-06-04T10:13:00.220-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Unit Testing" /><category scheme="http://www.blogger.com/atom/ns#" term="Pluralsight" /><title>Unit Test like a Secret Agent with Sinon.js</title><content type="html">&lt;em style="display: block; padding: 15px 10px 0px 50px;"&gt;The following content comes from the forth module of my Pluralsight course entitled: &lt;a href="http://bit.ly/etm-ps-testing" target="_blank"&gt;Front-End First: Testing and Prototyping JavaScript Apps&lt;/a&gt;. The rest of the course covers an introduction to Unit Testing, Examples of Hard to Test Code, &lt;a href="http://visionmedia.github.io/mocha/" target="_blank"&gt;Mocha&lt;/a&gt; (a JavaScript test runner), &lt;a href="http://gruntjs.com/" target="_blank"&gt;Grunt&lt;/a&gt; (a JavaScript task runner), &lt;a href="https://github.com/appendto/jquery-mockjax" target="_blank"&gt;Mockjax&lt;/a&gt; (a way to mock Ajax requests), &lt;a href="http://experiments.mennovanslooten.nl/2010/mockjson/" target="_blank"&gt;mockJSON&lt;/a&gt; (a way to generate semi-random complex objects for prototyping), and more.&lt;/em&gt;&lt;br /&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;&lt;br /&gt;
&lt;blockquote&gt;“Standalone test spies, stubs and mocks for JavaScript. No dependencies, works with any unit testing framework.”&lt;/blockquote&gt;&lt;br /&gt;
&lt;a href="http://sinonjs.org/" target="_blank"&gt;Sinon.js&lt;/a&gt; is a really helpful library when you want to unit test your code. It supports spies, stubs, and mocks. The library has cross browser support and also can run on the server using Node.js.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Spies&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-pxBTNF_ArMs/Ua13WoDSCtI/AAAAAAAAdKg/J6rQ271fM4Y/s1600/spy-vs-spy-courtesy-of-Mad-Magazine.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="245" src="http://4.bp.blogspot.com/-pxBTNF_ArMs/Ua13WoDSCtI/AAAAAAAAdKg/J6rQ271fM4Y/s400/spy-vs-spy-courtesy-of-Mad-Magazine.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/h2&gt;&lt;br /&gt;
&lt;blockquote style="width: 175px;"&gt;“A test spy is a function that records arguments, return value, the value of this and exception thrown (if any) for all its calls. A test spy can be an anonymous function or it can wrap an existing function.”&lt;/blockquote&gt;&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
A test spy records how it is used. It will record how many times it was called, what parameters were used, when it was called, and a bunch of other things. Here you can see an example of creating a spy and I've listed out only a small subset of it’s features such as &lt;code&gt;called&lt;/code&gt;, &lt;code&gt;callCount&lt;/code&gt;, &lt;code&gt;calledWith&lt;/code&gt;, &lt;code&gt;threw&lt;/code&gt;, &lt;code&gt;returned&lt;/code&gt;, and more.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=spy-methods.js"&gt;&lt;/script&gt;&lt;br /&gt;
In addition to just creating a new spy, you can also take an existing function and turn it into a spy. In this example we are taking jQuery and turning it’s &lt;code&gt;ajax&lt;/code&gt; method into a spy. Once the spy has been used you can actually pull out one of those instances and verify how that particular call was used. And again, it is important to restore the function back to it’s original state much like we did when we manually stubbed our functions previously.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=spy-ajax.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h4&gt;Mission Impossible: Spy&lt;/h4&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-uFVBU4kWWns/Ua18n6OTpAI/AAAAAAAAdLA/sVm7Vs2Sykg/s1600/e4m1_cruise_impossible.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="214" src="http://4.bp.blogspot.com/-uFVBU4kWWns/Ua18n6OTpAI/AAAAAAAAdLA/sVm7Vs2Sykg/s320/e4m1_cruise_impossible.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;In the following simple code example we are creating a new &lt;code&gt;ethanHunt&lt;/code&gt; spy and passing it to the &lt;code&gt;missionImpossible.start&lt;/code&gt; method. &lt;br /&gt;
&lt;br /&gt;
As you can see the &lt;code&gt;start&lt;/code&gt; method takes the agent that was passed in and immediately invokes it.&lt;br /&gt;
&lt;br /&gt;
The spy will record how it is used and then you can observe what happened.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=spy-mission-impossible.js"&gt;&lt;/script&gt;&lt;br /&gt;
At this point we can interrogate &lt;code&gt;ethanHunt&lt;/code&gt; if he was called or not, how many times it was called, and a bunch of other questions.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=spy-mission-impossible.sh"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Stubs&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-hHSd9oZ3mHk/Ua173s076CI/AAAAAAAAdK4/kk-GHBdN6Ls/s1600/Faker_by_Jackademus.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="266" src="http://2.bp.blogspot.com/-hHSd9oZ3mHk/Ua173s076CI/AAAAAAAAdK4/kk-GHBdN6Ls/s320/Faker_by_Jackademus.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/h3&gt;&lt;br /&gt;
&lt;blockquote style="width: 255px;"&gt;“Test stubs are functions (spies) with pre-programmed behavior. They support the full test spy API in addition to methods which can be used to alter the stub's behavior.”&lt;/blockquote&gt;&lt;br /&gt;
A stub in Sinon.js is also a spy as we've just seen, but it is also a function that has some predefined behavior. A stub is used when we want to fake some functionality so that our system thinks everything is performing normally.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
You'll see here that after we have created a stub we can optionally respond to it based on the parameters that are passed to it.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=stub-methods.js"&gt;&lt;/script&gt;&lt;br /&gt;
Here we are telling our stub that if &lt;code&gt;"Hello"&lt;/code&gt; is passed to it that it should return the string &lt;code&gt;"World"&lt;/code&gt; and if we pass &lt;code&gt;"Wuz"&lt;/code&gt; to the stub that &lt;code&gt;"Zup?"&lt;/code&gt; should be returned.&lt;br /&gt;
&lt;br /&gt;
We can do other things like if &lt;code&gt;"Kapow"&lt;/code&gt; is passed to our stub then an exception will be thrown and we can get even more sophisticated and say if an object is passed to the stub it should &lt;code&gt;yieldTo&lt;/code&gt; (or invoke) the &lt;code&gt;call&lt;/code&gt; function that was passing using the &lt;code&gt;"Howdy"&lt;/code&gt; argument. This is some pretty serious and awesome functionality built into these stubs!&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Mission Impossible: Stub&lt;/h4&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-28CwTjLsyZw/Ua14ph6u-II/AAAAAAAAdKs/2zbYJUkLBHg/s1600/mission_impossible_sml.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="147" src="http://1.bp.blogspot.com/-28CwTjLsyZw/Ua14ph6u-II/AAAAAAAAdKs/2zbYJUkLBHg/s320/mission_impossible_sml.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;In this next mission, if you choose to accept it... we are stubbing out a &lt;code&gt;tape&lt;/code&gt; function that will be passed into an assignment method.&lt;br /&gt;
&lt;br /&gt;
The tape will either be passed the string &lt;code&gt;"accept"&lt;/code&gt; or &lt;code&gt;"reject"&lt;/code&gt; and depending on the answer we want a different result. &lt;br /&gt;
&lt;br /&gt;
With a sinon stub, that is no problem. We can just say &lt;code&gt;tape.withArgs("accept"). returns(new Mission())&lt;/code&gt; and if we wanted to throw a &lt;code&gt;Disintegrate&lt;/code&gt; exception if the tape was rejected then we just follow the same pattern... &lt;code&gt;tape.withArgs("reject"). throws("Disintegrate")&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
If you can't tell already these stubs are really powerful and a great addition to your testing toolkit.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=stub-mission-impossible.js"&gt;&lt;/script&gt;&lt;br /&gt;
Once we've set up our stub, we can exercise our code as we would normally and the stub will respond with whatever behavior we predefined. Below you'll see that once we pass &lt;code&gt;"accept"&lt;/code&gt; that we are getting a &lt;code&gt;Mission&lt;/code&gt; object back and if we &lt;code&gt;"reject"&lt;/code&gt; the assignment that a &lt;code&gt;Disintegrate&lt;/code&gt; exception is thrown.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=stub-mission-impossible.sh"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h4&gt;Stubbed Unit Test&lt;/h4&gt;&lt;br /&gt;
Let’s take an example Twitter unit test and show how we can use a stub to simulate a response from jQuery’s &lt;code&gt;ajax&lt;/code&gt; method. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=stub-unit-test.js"&gt;&lt;/script&gt;&lt;br /&gt;
In the before hook we will ask Sinon.js to create us a new stub based off of jQuery’s &lt;code&gt;ajax&lt;/code&gt; method and we want to &lt;code&gt;yieldTo&lt;/code&gt; (or invoke) the success function from the object that is passed to it. And while we are at it we want to pass our fake twitter data along with the &lt;code&gt;success&lt;/code&gt; function.&lt;br /&gt;
&lt;br /&gt;
With that one line of code we have stubbed out the jQuery &lt;code&gt;ajax&lt;/code&gt; method and provide fake test data that we can use in our unit test.&lt;br /&gt;
&lt;br /&gt;
Again, it is important to clean up after ourselves so in the after hook at the bottom here we are taking the &lt;code&gt;jQuery.ajax&lt;/code&gt; method and calling restore which removes all of the stub behavior from the function, &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Mocks&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/--2X6ifXwlB4/Ua1_aE6czkI/AAAAAAAAdLQ/0Zn8HR_F5eo/s1600/4190127-833481-verified-rubber-stamp.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="148" src="http://1.bp.blogspot.com/--2X6ifXwlB4/Ua1_aE6czkI/AAAAAAAAdLQ/0Zn8HR_F5eo/s320/4190127-833481-verified-rubber-stamp.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/h3&gt;&lt;br /&gt;
&lt;blockquote style="width: 255px;"&gt;“Mocks (and mock expectations) are fake methods (like spies) with pre-programmed behavior (like stubs) as well as pre-programmed expectations. A mock will fail your test if it is not used as expected.”&lt;/blockquote&gt;&lt;br /&gt;
Now we finally get to mocks. Mocks are a lot like a stub and a spy, but with a slight twist. With a mock you define up front all of the things you want to expect ( or happen ) then when you are all done with your tests you assert that all those things happened as planned. So, it’s a slightly different way to think than if using a spy or stub by themselves.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
In the following code we are defining a mock based off our opts object and we are saying that we expect the call method should only be called once and when it is called that it should have the &lt;code&gt;"Hello World"&lt;/code&gt; string argument passed to it.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=mock-methods.js"&gt;&lt;/script&gt;&lt;br /&gt;
Then we proceed to run our code that we want tested. You'll see here I’m calling the call method passing the &lt;code&gt;"Hello World"&lt;/code&gt; string.&lt;br /&gt;
&lt;br /&gt;
And then at the end you tell the mock object to &lt;code&gt;mock.verify()&lt;/code&gt; that all of the expectations you've made previously are valid. If for some reason an expectation was not met, then an exception will occur. And then just like in most of the other examples, we need to clean up after ourselves and call the restore method off of what was mocked.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Mocked Unit Test&lt;/h4&gt;&lt;br /&gt;
Let’s take another look at the Twitter &lt;code&gt;getTweets&lt;/code&gt; unit tests again, but this time use a mock instead of a stub.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=mock-unit-test.js"&gt;&lt;/script&gt;&lt;br /&gt;
In the before hook I’m creating a mock of the jQuery object and I’m expecting that the ajax method will only be called one and that it should invoke the &lt;code&gt;success&lt;/code&gt; method of the object I pass in with some &lt;code&gt;fakeData&lt;/code&gt; I've provided.&lt;br /&gt;
&lt;br /&gt;
Inside my unit test I run the code I want to tests, which is the &lt;code&gt;getTweets&lt;/code&gt; method, and then on the callback I call the &lt;code&gt;verify&lt;/code&gt; method off of the mock to make sure my expectations have been met.&lt;br /&gt;
&lt;br /&gt;
And as before I restore the object in the after hook.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Fake Timers&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-B0A8bWz6lhM/Ua2AHTowpnI/AAAAAAAAdLY/Xe3UsW59AGA/s1600/SpyNet_Multi-Media_Video_Watch.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-B0A8bWz6lhM/Ua2AHTowpnI/AAAAAAAAdLY/Xe3UsW59AGA/s1600/SpyNet_Multi-Media_Video_Watch.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/h3&gt;&lt;br /&gt;
&lt;blockquote style="width: 300px;"&gt;“Fake timers is a synchronous implementation of setTimeout and friends that Sinon.JS can overwrite the global functions with to allow you to more easily test code using them.“&lt;/blockquote&gt;&lt;br /&gt;
Another handy feature of Sinon.s is that you can fake timers! At first this might seem strange, but it turns out it is really powerful and clever.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
We first start by asking Sinon.js to &lt;code&gt;useFakeTimers()&lt;/code&gt; and save off the clock it gives us. Now let’s take some jQuery animation code that will &lt;code&gt;fadeIn&lt;/code&gt; an element slowly onto the screen.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=fake-timer.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-5sKF-uFzCEU/Ua3u1s0errI/AAAAAAAAdMA/x0L7gu9zg-k/s1600/881-the-tardis_2239_detail.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-5sKF-uFzCEU/Ua3u1s0errI/AAAAAAAAdMA/x0L7gu9zg-k/s200/881-the-tardis_2239_detail.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;Normally if we wanted to test if this element showed up on the screen we'd either need to provide a callback when the animation is finished or tap into the promise created from the deferred and wait for that to resolve. &lt;br /&gt;
&lt;br /&gt;
However, much like a time lord we can take sinon’s TARDIS, errr... I mean fake timer and tell the clock that we are now 650 milliseconds in the future! And then we can immediately assert that the element is visible without waiting. And of course we will need to restore the clock back to normal when we are done.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Fake Server&lt;/h3&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-EBT-yADE9wQ/Ua2Be0r0sXI/AAAAAAAAdLw/JmAS9qQHiac/s1600/google-server-room5.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="213" src="http://4.bp.blogspot.com/-EBT-yADE9wQ/Ua2Be0r0sXI/AAAAAAAAdLw/JmAS9qQHiac/s320/google-server-room5.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote style="width: 250px;"&gt;“High-level API to manipulate FakeXMLHttpRequest instances.”&lt;/blockquote&gt;&lt;br /&gt;
Another neat feature that Sinon.js has is a fake server. This is a high level abstraction over the &lt;code&gt;FakeXMLHttpRequest&lt;/code&gt; that Sinon.js also provides if you need more granular support.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
We can create a fake server from Sinon.js, and we can define that for a GET to the /twitter/api/user.json resource we want to respond with a status code of 200 and the following JSON data. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=fake-server.js"&gt;&lt;/script&gt;&lt;br /&gt;
Then if we called jQuery’s &lt;code&gt;get&lt;/code&gt; method with the same URL then we'd get back the data we stubbed out. A key to remember is that you do need to tell the server to respond as we did immediately after we called the get method. And finally we need to restore the server when we are done.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Fake Server Unit Test&lt;/h4&gt;&lt;br /&gt;
Let’s take this technique and add it to our twitter unit test.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5703645.js?file=fake-server-unit-test.js"&gt;&lt;/script&gt;&lt;br /&gt;
In our &lt;code&gt;before&lt;/code&gt; hook we create the server and match the resource that our twitter app will be calling and pass back the data we want to stub out. Then we unit test out the &lt;code&gt;getTweets&lt;/code&gt; method as we did before, but things don't work out as we expect! Why is that? Well, it is because we are using JSONP as our jQuery ajax datatype. The way JSONP works is that it isn't actually using &lt;code&gt;XMLHttpRequest&lt;/code&gt; as a typical Ajax call does. Instead JSONP uses some trickery of injecting a dynamic script tag on your page and a bunch of other things that jQuery tries to hide from you for simplicities sake. &lt;br /&gt;
&lt;br /&gt;
So, in this case using the fake server won't help us. It would be better if we used a stub like we did in the last example.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Hopefully you can see that &lt;a href="http://sinonjs.org/" target="_blank"&gt;Sinon.js&lt;/a&gt; is a great utility library to help make unit testing a much more effective and terse experience. You'll probably more often than not find yourself making spies and stubs much more often than mocks, but that is really up to how you approach unit testing.&lt;br /&gt;
&lt;br /&gt;
If you enjoyed this content you can get more from my recent Pluralsight course entitled: &lt;a href="http://bit.ly/etm-ps-testing" target="_blank"&gt;Front-End First: Testing and Prototyping JavaScript Apps&lt;/a&gt; where I cover an introduction to Unit Testing, look at various examples of hard to test code and introduce the following libraries and tools... Mocha, Grunt, Mockjax, amplify.request, mockJSON, etc... &lt;br /&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/3102607897877275476/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/06/unit-test-like-secret-agent-with-sinonjs.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3102607897877275476?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3102607897877275476?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/06/unit-test-like-secret-agent-with-sinonjs.html" title="Unit Test like a Secret Agent with Sinon.js" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-pxBTNF_ArMs/Ua13WoDSCtI/AAAAAAAAdKg/J6rQ271fM4Y/s72-c/spy-vs-spy-courtesy-of-Mad-Magazine.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkADRH0ycSp7ImA9WhBbFUQ.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-4803560020456922890</id><published>2013-05-15T00:12:00.000-05:00</published><updated>2013-05-15T00:12:55.399-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-05-15T00:12:55.399-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Unit Testing" /><category scheme="http://www.blogger.com/atom/ns#" term="AmplifyJS" /><category scheme="http://www.blogger.com/atom/ns#" term="Pluralsight" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Testing and Prototyping JavaScript Applications</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://manor.im/etm-ps-testing" target="_blank"&gt;&lt;img border="0" height="108" src="http://2.bp.blogspot.com/-yXXhhxbcoF8/UZL9ZYuh1tI/AAAAAAAAbfU/V-i0lhimYVw/s640/front-end-first-testing-prototyping.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
I'm pleased to announce that I've finished my first course for Pluralsight entitled &lt;a href="http://manor.im/etm-ps-testing" target="_blank"&gt;Front-End First: Testing and Prototyping JavaScript Apps&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Years ago it was common for the back-end to have code coverage, but having unit tests for client-side JavaScript was difficult, cumbersome, and rare. Thankfully, today that is no longer the case. By using various tools and libraries such as &lt;a href="http://visionmedia.github.io/mocha/" target="_blank"&gt;Mocha&lt;/a&gt;, &lt;a href="http://sinonjs.org/" target="_blank"&gt;Sinon.js&lt;/a&gt;, and &lt;a href="http://gruntjs.com/" target="_blank"&gt;GruntJS&lt;/a&gt;&amp;nbsp;you can easily provide code coverage for your front-end as well.&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://manor.im/etm-ps-testing" target="_blank"&gt;&lt;img border="0" height="332" src="http://2.bp.blogspot.com/-ivmJGjSrXRU/UZL9JX3QtsI/AAAAAAAAbfM/njUfctr-R7I/s640/unit-testing-tools.png" width="640" /&gt;&lt;/a&gt;Historically a front-end developer had to wait until the back-end was complete before they could start truly building a functional User Interface. Thankfully today there are libraries such as &lt;a href="https://github.com/appendto/jquery-mockjax" target="_blank"&gt;Mockjax&lt;/a&gt;, &lt;a href="http://amplifyjs.com/api/request/" target="_blank"&gt;AmplifyJS&lt;/a&gt;, and &lt;a href="https://github.com/mennovanslooten/mockJSON" target="_blank"&gt;mockJSON&lt;/a&gt; that can enable you to simulate the interactions with the back-end before its even complete. By doing so, this enables a front-end developer to work independently from the back-end and allows both teams to efficiently work within their speciality. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/4803560020456922890/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/05/testing-and-prototyping-javascript.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4803560020456922890?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4803560020456922890?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/05/testing-and-prototyping-javascript.html" title="Testing and Prototyping JavaScript Applications" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-yXXhhxbcoF8/UZL9ZYuh1tI/AAAAAAAAbfU/V-i0lhimYVw/s72-c/front-end-first-testing-prototyping.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0YFRXw6cSp7ImA9WhBWGUQ.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-5064695092611698177</id><published>2013-04-12T00:30:00.000-05:00</published><updated>2013-04-14T20:58:34.219-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-14T20:58:34.219-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Backbone" /><category scheme="http://www.blogger.com/atom/ns#" term="Conference" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>AngleBrackets Sessions and Slides</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://www.anglebrackets.org/" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="45" src="http://3.bp.blogspot.com/-CkIyOCFlj-8/UWdQYeHP6II/AAAAAAAAZ_U/ca0jzjKiK-g/s320/anglebrackets.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;I had a great time this week at the &lt;a href="http://www.anglebrackets.org/"&gt;AngleBrackets &lt;/a&gt;conference in Las Vegas, NV. It was the first year for this web focused conference.&lt;br /&gt;
&lt;br /&gt;
I was honored to speak alongside John Papa (&lt;a href="http://twitter.com/john_papa"&gt;@john_papa&lt;/a&gt;), Dan Wahlin (&lt;a href="http://twitter.com/danwahlin"&gt;@danwahlin&lt;/a&gt;), Scott Hanselman (&lt;a href="http://twitter.com/shanselman"&gt;@shanselman&lt;/a&gt;), Christian Heilmann (&lt;a href="http://twitter.com/codepo8"&gt;@codepo8&lt;/a&gt;), Lea Verou (&lt;a href="http://twitter.com/LeaVerou"&gt;@LeaVerou&lt;/a&gt;), Denise Jacobs (&lt;a href="http://twitter.com/denisejacobs"&gt;@denisejacobs&lt;/a&gt;), Jim Cowart (&lt;a href="http://twitter.com/ifandelse"&gt;@ifandelse&lt;/a&gt;), Todd Anglin (&lt;a href="http://twitter.com/toddanglin"&gt;@toddanglin&lt;/a&gt;), Burke Holland (&lt;a href="http://twitter.com/burkeholland"&gt;@burkeholland&lt;/a&gt;), and more....&lt;br /&gt;
&lt;br /&gt;
Thanks you for everyone who was able to attend my talks. It was great to meet you all. I enjoyed our conversations and your questions. I hope to see you all around at another conference in the near future! The following are the talks that I gave this past week.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Angry Birds of JavaScript&lt;/h3&gt;&lt;br /&gt;
AngleBrackets was the first time I've given my Angry Birds of JavaScript talk based on the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;blog series&lt;/a&gt;&lt;/strong&gt; that ended yesterday. You can click the following image to see the slides.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;I used the reveal.js slide presentation framework for my slides. You'll need to down-arrow down to drill into each topic and then right-arrow to the next topic. The last slide of the Red Angry Bird is an interactive game. You have to destroy both pigs before you can proceed to the next topic ;)&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://elijahmanor.github.io/talks/angry-birds-javascript/index.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="358" src="http://1.bp.blogspot.com/-Sc48YX-sHXg/UWdbkH0NIAI/AAAAAAAAZ_0/NzzHr2kqiNk/s640/angry-birds-cover-600.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Introduction to Backbone.js&lt;/h3&gt;&lt;br /&gt;
I've given this talk once before, but I tweaked the slides somewhat since then. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://elijahmanor.github.io/talks/intro-to-backbonejs/index.html" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="414" src="http://1.bp.blogspot.com/-uL6GMGiYdx0/UWdbuLY8NuI/AAAAAAAAZ_8/PEu8bbvdGUA/s640/intro-to-backbone-cover-600.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Other Sessions&lt;/h3&gt;&lt;br /&gt;
You can view the &lt;a href="http://www.anglebrackets.org/downloads.aspx" target="_blank"&gt;slides from the other sessions&lt;/a&gt; at the AngleBrackets website.&lt;br /&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/5064695092611698177/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/anglebrackets-sessions-and-slides.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5064695092611698177?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5064695092611698177?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/anglebrackets-sessions-and-slides.html" title="AngleBrackets Sessions and Slides" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-CkIyOCFlj-8/UWdQYeHP6II/AAAAAAAAZ_U/ca0jzjKiK-g/s72-c/anglebrackets.png" height="72" width="72" /><thr:total>1</thr:total></entry><entry gd:etag="W/&quot;DEMBRnk6eSp7ImA9WhBWF0s.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-1352296146812523011</id><published>2013-04-11T00:05:00.000-05:00</published><updated>2013-04-12T06:34:17.711-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-12T06:34:17.711-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Mighty Eagle - Automation</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/4QG5Q/ http://plnkr.co/edit/syYXSOWx1UWUlbFAd0v9 --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-N7kG4eOFXzA/UWED8Hv6eiI/AAAAAAAAZ2g/bzakzkoKQgc/s1600/Angry-Birds-for-iOS-Mighty-Eagle-screenshot.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="197" src="http://2.bp.blogspot.com/-N7kG4eOFXzA/UWED8Hv6eiI/AAAAAAAAZ2g/bzakzkoKQgc/s400/Angry-Birds-for-iOS-Mighty-Eagle-screenshot.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-9CHfr07ovWs/UWEETqEvgSI/AAAAAAAAZ2w/baqRjP09l1c/s1600/angrybirds-eagle.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="235" src="http://4.bp.blogspot.com/-9CHfr07ovWs/UWEETqEvgSI/AAAAAAAAZ2w/baqRjP09l1c/s320/angrybirds-eagle.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Bird - RequireJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html" target="_blank"&gt;Black Bird - Backbone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html" target="_blank"&gt;White Bird - Linting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html" target="_blank"&gt;Green Bird - Mocking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-orange-bird.html" target="_blank"&gt;Orange Bird - Templating&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-big-brother.html" target="_blank"&gt;Big Brother Bird - Patterns&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Mighty Eagle Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the Mightly Eagle who uses the most superior weapon of them all, a suite of tools that can organize and deploy all the other birds into battle against their soon to be vanquished foe. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
Over time the birds picked up RequireJS (Yellow Bird), JSHint (White Bird), Plato, Mustache (Orange Bird), and a bunch of other great tools, but all of them required a command line task to complete. It was getting quite annoying having to remember what was required to run each of these tools. In addition, it was easy to forget to run the tools to update their web application when necessary. Thankfully one day the Mighty Eagle introduced some tools to make things a little bit easier. The Eagle brought Grunt and Bowser to automate common tasks and to help easily bring in commonly used libraries that were necessary to e their applications.  &lt;br /&gt;
&lt;br /&gt;
However, during a recent invasion the pigs stole the birds' Gang of Foul book! As a result, one of the Big Brother Birds has been tasked to reclaim what has been stolen. He will use his overwhelming power of trickery to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-CXGuzyWVyk8/UWELb7hUEQI/AAAAAAAAZ3g/joO4tCJ_eyc/s1600/toolset+(2).png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-CXGuzyWVyk8/UWELb7hUEQI/AAAAAAAAZ3g/joO4tCJ_eyc/s200/toolset+(2).png" width="163" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;Grunt&lt;/h2&gt;&lt;br /&gt;
Grunt is a task-based command line tool that is written in JavaScript and helps automate the build of your front-end application. The community has really grabbed on to this tool and as a result there are tons of plugins that you can choose from to automate things like CoffeeScript, handlebars precompilation, less support, JSHint checking, etc...&lt;br /&gt;
&lt;br /&gt;
Several really large projects already use Grunt to assist their builds and other automation tasks such as Twitter, jQuery, Modernizr, Sauce Labs, and others.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Getting Started&lt;/h3&gt;&lt;br /&gt;
In order to get started you just need to install grunt from node with the following command...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5331806.js?file=grunt-install.sh"&gt;&lt;/script&gt;&lt;br /&gt;
Once you've installed grunt you'll need 2 main things for each of your projects&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Gruntfile.js&lt;/li&gt;
&lt;li&gt;package.json&lt;/li&gt;
&lt;/ol&gt;&lt;br /&gt;
&lt;h4&gt;Gruntfile.js&lt;/h4&gt;&lt;br /&gt;
You can create your own &lt;code&gt;Gruntfile.js&lt;/code&gt; from scratch, you can copy a starter Gruntfile.js from the documentation, or there is a use a &lt;code&gt;grunt-init gruntfile&lt;/code&gt; project scaffold. To install the scaffold follow the instructions from Grunt's &lt;a href="http://gruntjs.com/project-scaffolding" target="_blank"&gt;Project Scaffolding&lt;/a&gt; page. The following Gruntfile.js is an example from Grunt's &lt;a href="http://gruntjs.com/getting-started" target="_blank"&gt;Get Started&lt;/a&gt; page...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5331806.js?file=Gruntfile.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h4&gt;package.json&lt;/h4&gt;&lt;br /&gt;
The &lt;code&gt;package.json&lt;/code&gt; describes your project's name, version, and any dependencies it might have such as grunt and any grunt plugins. You can copy an example package.json from the Grunt's &lt;a href="http://gruntjs.com/getting-started" target="_blank"&gt;Get Started&lt;/a&gt; page... (see below)&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5331806.js?file=package.json"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h4&gt;Grunt Plugins&lt;/h4&gt;&lt;br /&gt;
Now that hopefully everything is setup, you can start using a whole suite of plugins to automate tasks. Here are a few interesting ones that you might enjoy...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;grunt-contrib-coffee - Compile CoffeeScript files into JavaScript&lt;/li&gt;
&lt;li&gt;grunt-contrib-compass - Compile Compass into CSS&lt;/li&gt;
&lt;li&gt;grunt-contrib-concat - Concatenates files&lt;/li&gt;
&lt;li&gt;grunt-contrib-connect - Starts a connect web server&lt;/li&gt;
&lt;li&gt;grunt-contrib-csslint - Lints your CSS files&lt;/li&gt;
&lt;li&gt;grunt-contrib-handlebars - Precompiles your Handlebar tempaltes&lt;/li&gt;
&lt;li&gt;grunt-contrib-htmlmin - Minify your HTML markup&lt;/li&gt;
&lt;li&gt;grunt-contrib-imagemin - Minify PNG and JPEG images&lt;/li&gt;
&lt;li&gt;grunt-contrib-jshint - Validate files with JSHint&lt;/li&gt;
&lt;li&gt;grunt-contrib-less - Compile LESS to CSS&lt;/li&gt;
&lt;li&gt;grunt-contrib-nodeunit - Run Nodeunit unit test&lt;/li&gt;
&lt;li&gt;grunt-contrib-watch - Run predefined tasks when files change&lt;/li&gt;
&lt;li&gt;grunt-contrib-requirejs - Optimize RequireJS projects using r.js&lt;/li&gt;
&lt;li&gt;grunt-contrib-uglify - Minify files with UglifyJS&lt;/li&gt;
&lt;li&gt;grunt-contrib-yuidoc - Compile YUIDocs Documentation&lt;/li&gt;
&lt;li&gt;... more ...&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h4&gt;jQuery's Gruntfile&lt;/h4&gt;&lt;br /&gt;
I pulled down jQuery from their GitHub repository to see how they use Grunt and the following is the output when get when executing the tool. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-qdV01Mu1uO4/UWJLrncu2WI/AAAAAAAAZ4A/bges3xKOJ_o/s1600/grunt-jquery.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="554" src="http://2.bp.blogspot.com/-qdV01Mu1uO4/UWJLrncu2WI/AAAAAAAAZ4A/bges3xKOJ_o/s640/grunt-jquery.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
If you look closely you'll notice they update their git submodules, build a version of jQuery from it's modules, run JSHint against the built jquery.js and tests files, creates sourcemaps, and runs a special compare file size task. If you dig deep into their Gruntfile you'll find they've also setup a custom way to run their unit tests against Browserstack, which is pretty cool if you ask me ;)&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Modernizr's Gruntfile&lt;/h4&gt;&lt;br /&gt;
In the same way I pulled down the Modernizr repository and typed &lt;code&gt;grunt qunit&lt;/code&gt; to watch their 746 unit tests execute and pass in 369ms using the PhantomJS headless browser! &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XvfSNrxCTMQ/UWJLxIfNMPI/AAAAAAAAZ4M/AXAjvelHjZQ/s1600/grunt-modernizr.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="168" src="http://1.bp.blogspot.com/-XvfSNrxCTMQ/UWJLxIfNMPI/AAAAAAAAZ4M/AXAjvelHjZQ/s640/grunt-modernizr.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Grunt Resources&lt;/h3&gt;&lt;br /&gt;
The intent of this post wasn't to teach you all there is to know about Grunt, but to make you aware of it if you didn't know already. It is a very nice tool to help you automatic ALL THE front-end THINGS. Check out the following resources to help you unpack how to get started...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.youtube.com/watch?v=q3Sqljpr-Vc"&gt;The Grunt Basics&lt;/a&gt; by Cary Landholt (&lt;a href="http://twitter.com/carylandholt" target="_blank"&gt;@carylandholt&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://merrickchristensen.com/articles/gruntjs-workflow.html" target="_blank"&gt;Grunt.js Workflow&lt;/a&gt; by Merrick Christensen (&lt;a href="http://twitter.com/iammerrick" target="_blank"&gt;@iammerrick&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/meeting-grunt-the-build-tool-for-javascript/" target="_blank"&gt;Meet Grunt: The Build Tool for JavavScript&lt;/a&gt; by Andrew Burgess (&lt;a href="http://twitter.com/andrew8088" target=""&gt;@andrew8088&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-L7pXsxuBnVA/UWELyS9lG0I/AAAAAAAAZ3w/ptGkkE9j1ms/s1600/toolset+(3).png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-L7pXsxuBnVA/UWELyS9lG0I/AAAAAAAAZ3w/ptGkkE9j1ms/s200/toolset+(3).png" width="161" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;Twitter Bower&lt;/h2&gt;&lt;br /&gt;
For those of you that have used Node or Ruby you'll be familiar with npm or gems, however, there hasn't been anything like that for front-end browser scripts and styles... at least until now! &lt;br /&gt;
&lt;br /&gt;
The Twitter Bower project seeks to solve that problem by providing a package manager for the web (HTML, CSS, and JavaScript). &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5331806.js?file=bower-install.sh"&gt;&lt;/script&gt;&lt;br /&gt;
Once you've installed bowser, then you can start downloading libraries! For example, if we wanted to pull down the latest version of jQuery we could just &lt;code&gt;bower install jquery&lt;/code&gt; and you'll see the following...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-s8ERF-X_x70/UWLBuSeWcpI/AAAAAAAAZ4Y/uWUIb5eWuLg/s1600/bower-install-jquery.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="436" src="http://3.bp.blogspot.com/-s8ERF-X_x70/UWLBuSeWcpI/AAAAAAAAZ4Y/uWUIb5eWuLg/s640/bower-install-jquery.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-Rp0_He-oQgI/UWELh24_5kI/AAAAAAAAZ3o/J8F2Jj_LV4w/s1600/toolset+(1).png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-Rp0_He-oQgI/UWELh24_5kI/AAAAAAAAZ3o/J8F2Jj_LV4w/s200/toolset+(1).png" width="150" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Bower Resources&lt;/h3&gt;&lt;br /&gt;
If you want to find out more about bower then I encourage you to check out some of the nice resources below.&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/tools-and-tips/meet-bower-a-package-manager-for-the-web/"&gt;Meet Bower: A Package Manager For The Web&lt;/a&gt; by Andrew Burgess (&lt;a href="http://twitter.com/andrew8088" target="_blank"&gt;@andrew8088&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/a-requirejs-backbone-and-bower-starter-template/"&gt;A RequireJS, Backbone, and Bower Starter Template&lt;/a&gt; by Jeffrey Way (&lt;a href="http://twitter.com/jeffrey_way" target="_blank"&gt;@jeffrey_way&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Yeoman&lt;/h2&gt;&lt;br /&gt;
The yeoman project is a scaffolding engine that works along with Grunt and Bower. You can think of yeoman as the scaffolding piece that can get your applications going quickly. In order to get started you need to install yeoman by using the following syntax...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5331806.js?file=yo-install.sh"&gt;&lt;/script&gt;&lt;br /&gt;
Once yeoman is installed then you can generate a variety of different types of projects. In the following screenshot I asked yeoman to create a new webapp. It will ask me several questions along the way to tailor the application to my needs.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-hgpccVDN7Gg/UWLB_oM2gWI/AAAAAAAAZ4g/_XFTx_MJsTw/s1600/yo-webapp.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-hgpccVDN7Gg/UWLB_oM2gWI/AAAAAAAAZ4g/_XFTx_MJsTw/s640/yo-webapp.png" width="592" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
There are other scaffolds such as &lt;a href="https://github.com/yeoman/generator-backbone" target="_blank"&gt;Backbone&lt;/a&gt;, &lt;a href="https://github.com/yeoman/generator-angular" target="_blank"&gt;AngularJS&lt;/a&gt;, etc... that you can install and get your project underway. You can view a list of &lt;a href="https://github.com/yeoman" target="_blank"&gt;more generators&lt;/a&gt; from the Yeoman GitHub page.&lt;br /&gt;
&lt;br /&gt;
For example in the following screenshots I first create a new Backbone app and then immediately create a new &lt;code&gt;bird&lt;/code&gt; model.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-WADbKLpIFUA/UWLSpw7ya6I/AAAAAAAAZ4w/QrqLbXZ8AD8/s1600/yo-backbone-app.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-WADbKLpIFUA/UWLSpw7ya6I/AAAAAAAAZ4w/QrqLbXZ8AD8/s640/yo-backbone-app.png" width="606" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-RO_QnEkhVnw/UWLS_Y-HNBI/AAAAAAAAZ44/I7jZC_SJGZA/s1600/yo-backbone-model.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="80" src="http://1.bp.blogspot.com/-RO_QnEkhVnw/UWLS_Y-HNBI/AAAAAAAAZ44/I7jZC_SJGZA/s640/yo-backbone-model.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Yeoman is currently 1.0 beta and the website says there are some issues with Windows. I've been able to use it to some extend, but I'm sure there are some features that aren't yet supported, but the plan is to have it fully supported.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Mighty Eagle Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/GWDDv/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-KQKPPj6GV_I/UWEKCNFskjI/AAAAAAAAZ3A/eufuyrkvR2I/s1600/eagle-game.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Embracing Grunt, Bower, and Yeoman can help automate various parts of your development, testing, and deployment process. The community for these tools are very active and you can find plugins to help cater these to your application's needs. &lt;br /&gt;
&lt;br /&gt;
There is one more front-end architecture technique that has been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/1352296146812523011/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-mighty-eagle.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1352296146812523011?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1352296146812523011?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-mighty-eagle.html" title="Angry Birds of JavaScript: Mighty Eagle - Automation" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-N7kG4eOFXzA/UWED8Hv6eiI/AAAAAAAAZ2g/bzakzkoKQgc/s72-c/Angry-Birds-for-iOS-Mighty-Eagle-screenshot.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMGSHk8eyp7ImA9WhBWF04.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-4785154623040670142</id><published>2013-04-10T00:05:00.000-05:00</published><updated>2013-04-11T22:13:49.773-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-11T22:13:49.773-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Big Brother Bird - Patterns</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/4QG5Q/ http://plnkr.co/edit/syYXSOWx1UWUlbFAd0v9 --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-mwxJ0DGmvGI/UWCKOt-Lx6I/AAAAAAAAZ14/od_wDw_B5mk/s1600/angry-birds-big-red-bird.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="180" src="http://3.bp.blogspot.com/-mwxJ0DGmvGI/UWCKOt-Lx6I/AAAAAAAAZ14/od_wDw_B5mk/s320/angry-birds-big-red-bird.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-wqME_pIXlMg/UWCKU5PVcVI/AAAAAAAAZ2A/yoODl8TYwKU/s1600/big-brother-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-wqME_pIXlMg/UWCKU5PVcVI/AAAAAAAAZ2A/yoODl8TYwKU/s1600/big-brother-bird.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Bird - RequireJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html" target="_blank"&gt;Black Bird - Backbone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html" target="_blank"&gt;White Bird - Linting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html" target="_blank"&gt;Green Bird - Mocking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-orange-bird.html" target="_blank"&gt;Orange Bird - Templating&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Big Brother Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the Big Brother Bird who pulls out the big guns with his finite state machine and other proven design patterns of destruction. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
The birds knew how to program for the most part, but they never had a common terminology that they all understood to represent common scenarios they kept encountering. Then one day a Big Brother Bird came along and documented a set of common Design Patterns and them names and descriptions so they could all be on the same page when talking about architecture. Big Brother Bird ended up writing these patterns in a popular piece that became known as the &lt;strong&gt;Gang of Foul&lt;/strong&gt; book.&lt;br /&gt;
&lt;br /&gt;
However, during a recent invasion the pigs stole the birds' Gang of Fowl book! As a result, one of the Big Brother Birds has been tasked to reclaim what has been stolen. He will use his overwhelming power of trickery to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Gang of Fowl Patterns&lt;/h2&gt;&lt;br /&gt;
&lt;div style="width: 100%;"&gt;&lt;div style="float: left; width: 33%;"&gt;&lt;h3&gt;Creational Patterns&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Abstract Factory&lt;/li&gt;
&lt;li&gt;Builder&lt;/li&gt;
&lt;li&gt;Factory Method&lt;/li&gt;
&lt;li&gt;Prototype&lt;/li&gt;
&lt;li&gt;Singleton&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;div style="float: right; width: 33%;"&gt;&lt;h3&gt;Structural Patterns&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Adapter&lt;/li&gt;
&lt;li&gt;Bridge&lt;/li&gt;
&lt;li&gt;Composite&lt;/li&gt;
&lt;li&gt;Decorator&lt;/li&gt;
&lt;li&gt;Facade&lt;/li&gt;
&lt;li&gt;Flyweight&lt;/li&gt;
&lt;li&gt;Proxy&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;div style="float: right; width: 33%;"&gt;&lt;h3&gt;Behavioral Patterns&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;Chain of Resp.&lt;/li&gt;
&lt;li&gt;Command&lt;/li&gt;
&lt;li&gt;Interpreter&lt;/li&gt;
&lt;li&gt;Iterator&lt;/li&gt;
&lt;li&gt;Mediator&lt;/li&gt;
&lt;li&gt;Memento&lt;/li&gt;
&lt;li&gt;Observer&lt;/li&gt;
&lt;li&gt;State&lt;/li&gt;
&lt;li&gt;Strategy&lt;/li&gt;
&lt;li&gt;Template Method&lt;/li&gt;
&lt;li&gt;Visitor&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;Some These Patterns in JavaScript&lt;/h2&gt;&lt;br /&gt;
&lt;h3&gt;Singleton&lt;/h3&gt;&lt;br /&gt;
The most basic form of singleton is the object literal as shown below. We are basically just creating an object and there is one of them. Technically someone could &lt;code&gt;Object.create&lt;/code&gt; on us, but for the most part this fulfills the singleton definition. You can find a more robust solution in one of the resources recommended near the end of this post.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=singleton.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Factory&lt;/h3&gt;&lt;br /&gt;
A factory is a way to create new objects without actually using the &lt;code&gt;new&lt;/code&gt; keyword. The idea is that there is something abstracted away from you in the factory method. In the following example we are aren't necessarily doing anything fancy, but you could imagine that we could add some custom code down the road and the external API wouldn't change, which is the point of this pattern.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=factory.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Bridge&lt;/h3&gt;&lt;br /&gt;
In the following snippet of code we are creating a small bridge between an event handler and the code that will be executed. By creating a little bridge it will enabled the executed code to be tested easier since it won't have a dependency on the element context that was passed by jQuery.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=bridge.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Facade&lt;/h3&gt;&lt;br /&gt;
A facade is common place in front-end web development since there is so much cross-browser inconsistencies. A facade brings a common API to something that could vary under the covers. In the following snippet we abstract the addEventListener logic for various browser implementations.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=facade.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Adapter&lt;/h3&gt;&lt;br /&gt;
An adapter is a nice way to massage one piece of code to work with another piece of code. This can be useful when you need to switch to another library, but can't afford to rewrite much of your code. In the following example we are modifying jQuery's &lt;code&gt;$.when&lt;/code&gt; method to work with the &lt;code&gt;WinJS.Promise&lt;/code&gt;. This is some code I wrote back when I worked for appendTo when we were making jQuery working with Windows 8 apps. You can find this repository at &lt;a href="https://github.com/appendto/jquery-win8" target="_blank"&gt;jquery-win8&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Much of the jquery-win8 repository is not needed anymore since Jonathan Sampson has worked with the jQuery team to make sure the changes he made to the shim was added to the 2.0 version of jQuery as noted in the &lt;a href="http://appendto.com/blog/2013/03/windows-store-applications-with-jquery-2-0/" target="_blank"&gt;following blog post&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=adapter.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Observer&lt;/h3&gt;&lt;br /&gt;
We've covered the Observer pattern already in the &lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird&lt;/a&gt; past a while back in this series, but it is a powerful pattern that can help decouple various components. My recommendation is to use the &lt;a href="https://github.com/postaljs/postal.js" target="_blank"&gt;postal.js library&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=observer.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Many More Patterns&lt;/h2&gt;&lt;br /&gt;
&lt;h3&gt;Inheritance&lt;/h3&gt;&lt;br /&gt;
There are several ways to implement inheritance in JavaScript. It is good to know some of these patterns as you create new objects in your application.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Prototypal Inheritance&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=prototypal-inheritance.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;strong&gt;Pseudoclassical Ineritance&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=pseudoclassical-inheritance.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Chaining&lt;/h3&gt;&lt;br /&gt;
In the front-end world chaining became popular by the jQuery library. It is actually a really easy pattern to implement. You essentially just have to return &lt;code&gt;this&lt;/code&gt; from every function so that other functions can be immediately called. See the following for an example.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=chaining.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Encapsulating&lt;/h3&gt;&lt;br /&gt;
We've already covered encapsulating in the &lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird&lt;/a&gt; past where we talked about the IIFE pattern. This allows you to have public and private properties and methods to help encapsulate your code. The follow is a very brief example of that. Check out the &lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird&lt;/a&gt; post for more details.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=encapsulating.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Finite State Machine&lt;/h3&gt;&lt;br /&gt;
One of my favorite pattern is the Finite State Machine. My friend Jim Cowart (&lt;a href="http://twitter.com/ifandelse" target="_blank"&gt;@ifandelse&lt;/a&gt;) created the &lt;a href="https://github.com/ifandelse/machina.js" target="_blank"&gt;Machina.js Library&lt;/a&gt; to implement this pattern in JavaScript. The following is an example of using states to describe the game of Angry Birds. For more information check out his &lt;a href="http://freshbrewedcode.com/jimcowart/2012/03/12/machina-js-finite-state-machines-in-javascript/" target="_blank"&gt;blog post&lt;/a&gt; and &lt;a href="https://github.com/ifandelse/machina.js" target="_blank"&gt;GitHub repository&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5328936.js?file=finite-state-machine.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Recommendations&lt;/h2&gt;&lt;br /&gt;
In addition to learning these patterns I would recommend that you pick one of your favorite libraries and start to source dive into their repository. There is a wealth of information you can learn there. At first it could be semi-overwhelming, but over time you can glean a lot from developers who really know some of these patterns. You might try just looking at one particular method and start picking it apart. If you aren't sure exactly where to look for a particular method why don't you pick jQuery and use James Padolsey's (&lt;a href="http://twitter.com/padosley" target="_blank"&gt;@padosley&lt;/a&gt;) &lt;a href="http://james.padolsey.com/jquery/" target="_blank"&gt;jQuery Source Viewer&lt;/a&gt; to help find it for you?&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Additional Resources&lt;/h2&gt;&lt;br /&gt;
There are far too many patterns for me to list here. Many have blogged about these before me and will continue to. If I have missed any good ones please let me know.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.joezimjs.com/javascript/javascript-design-patterns-singleton/" target="_blank"&gt;JavaScript Design Patterns&lt;/a&gt; by Joe Zim (&lt;a href="http://twitter.com/JoeZimJS" target="_blank"&gt;@JoeZimJS&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/digging-into-design-patterns-in-javascript/" target="_blank"&gt;Understanding Design Patterns in JavaScript&lt;/a&gt; by Tilo Mitra (&lt;a href="http://twitter.com/tilomitra" target="_blank"&gt;@tilomitra&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://addyosmani.com/resources/essentialjsdesignpatterns/book/" target="_blank"&gt;Learning JavaScript Design Patterns&lt;/a&gt; by Addy Osmani (&lt;a href="http://twitter.com/addyosmani" target="_blank"&gt;@addyosmani&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://shichuan.github.io/javascript-patterns/" target="_blank"&gt;JS Patterns&lt;/a&gt; by Shi Chuan (&lt;a href="http://twitter.com/shichuan" target="_blank"&gt;@shichuan&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://shop.oreilly.com/product/9780596806767.do" target="_blank"&gt;JavaScript Patterns&lt;/a&gt; by Stoyan Stefanov (&lt;a href="http://twitter.com/xyz" target="_blank"&gt;@xyz&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://shop.oreilly.com/product/9780596517748.do" target="_blank"&gt;JavaScript: The Good Parts&lt;/a&gt; by Douglas Crockford&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Big Brother Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/k6VCt/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-HjiGrN3B7jg/UWDO-fHTJgI/AAAAAAAAZ2Q/-sshCm882k4/s1600/big-brother-bird-game.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
The good news is you don't have to know all the answers to be successful in front-end web development, but what does help is knowing some of the common patterns that come up again and again during development. Once you get accustomed to these patterns it will become easier talking about these architectural solutions and figure out solutions should come quicker. Take some time and look through the recommended resources above and start mulling over some of them for yourself.  &lt;br /&gt;
&lt;br /&gt;
There is one more front-end architecture technique that has been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/4785154623040670142/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-big-brother.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4785154623040670142?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4785154623040670142?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-big-brother.html" title="Angry Birds of JavaScript: Big Brother Bird - Patterns" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-mwxJ0DGmvGI/UWCKOt-Lx6I/AAAAAAAAZ14/od_wDw_B5mk/s72-c/angry-birds-big-red-bird.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEMARn06eCp7ImA9WhBWF04.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-778640207951909205</id><published>2013-04-09T00:05:00.000-05:00</published><updated>2013-04-11T22:14:07.310-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-11T22:14:07.310-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Orange Bird - Templating</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/4QG5Q/ http://plnkr.co/edit/syYXSOWx1UWUlbFAd0v9 https://github.com/gruntjs/grunt-contrib-handlebars --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-EoYTO-3jfeY/UV-WOmhaF3I/AAAAAAAAZ0g/S1oYMzsOg2w/s1600/angrybirds_620_121112.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="160" src="http://1.bp.blogspot.com/-EoYTO-3jfeY/UV-WOmhaF3I/AAAAAAAAZ0g/S1oYMzsOg2w/s320/angrybirds_620_121112.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-MsnBfq6yXiQ/UV-aF4EH1EI/AAAAAAAAZ0o/bUCCPM5vfUQ/s1600/Orange_bird_space.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-MsnBfq6yXiQ/UV-aF4EH1EI/AAAAAAAAZ0o/bUCCPM5vfUQ/s1600/Orange_bird_space.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Bird - RequireJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html" target="_blank"&gt;Black Bird - Backbone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html" target="_blank"&gt;White Bird - Linting&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html" target="_blank"&gt;Green Bird - Mocking&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Orange Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the Orange Bird. He first starts out small with a simple template, but then expands itself into a DOM blast that will surely send the message that the birds mean business. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
For the last several years we have seen a trend that more and more work is being done on the front-end of web development. We communicate to the back-end via Ajax or Web Sockets and then display the data somehow in the UI. The birds found themselves mostly using string concatenation to build up the rich user interfaces, which resulted in a lot of code that was boring and also prone for errors. Thankfully an Orange Bird came along and said, "Hey, isn't there something better than this? Can't we separate our view from our data somehow?", and that is how templates became to be in the bird world. The Orange Bird borrowed templating libraries from the humans such as Underscore.js and &lt;a href="http://handlebarsjs.com/" target="_blank"&gt;Handlebar.js&lt;/a&gt; to help fit this need among the foul. &lt;br /&gt;
&lt;br /&gt;
However, during a recent invasion the pigs stole the birds' templating libraries! As a result, one of the Orange Birds has been tasked to reclaim what has been stolen. He will use his exploding power to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Why Use a Templating Engine?&lt;/h2&gt;&lt;br /&gt;
Before we get into what templating engines I recommend let's first look into why we might need one in the first place. The more I develop I try to find ways to separate the various parts of my application. I start to feel dirty when too much stuff is going on in the same place. Take a look at the following piece of code and tell me how you feel...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=before.js"&gt;&lt;/script&gt;&lt;br /&gt;
Yeah, I don't like all of the string concatenation either. I prefer not to have a bunch of presentation inside of my code if I can help it. On the plus side, it does work. You can see the output of the code in the following embedded jsFiddle.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="200" src="http://jsfiddle.net/B4fJB/embedded/result,js,html" width="100%"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
So, what can we do instead? This is where some type of templating engine can help us simplify our code and separate our markup from our code.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Underscore.js&lt;/h2&gt;&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-t24RSU2yVNo/UWBpxcuBmUI/AAAAAAAAZ1I/1GQ-k_JuODA/s1600/underscore.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="55" src="http://1.bp.blogspot.com/-t24RSU2yVNo/UWBpxcuBmUI/AAAAAAAAZ1I/1GQ-k_JuODA/s320/underscore.png" width="320" /&gt;&lt;/a&gt;We will first look at the template method in the Underscore.js library. I tend to use Underscore in all of my projects these days so I already have the power of its templating engine loaded. If what I am doing is pretty simple, then I mostly default to use Underscore for templating. However, as you'll see there are some limitations which make the next library we will look at much more appealing.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Take 1&lt;/h3&gt;&lt;br /&gt;
The following is the above code rewritten using Underscore's template. You'll notice that the code piece has been greatly simplified! Whoo hooo! &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=underscore-before.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-3Kf0njai3FE/UWQqiAbjkII/AAAAAAAAZ5I/uqisM5XsOCQ/s1600/Inflated_orange_bird_sprite.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="178" src="http://3.bp.blogspot.com/-3Kf0njai3FE/UWQqiAbjkII/AAAAAAAAZ5I/uqisM5XsOCQ/s200/Inflated_orange_bird_sprite.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;The bulk of the work is being done by the template to explode it into a bunch of markup! As you can see to the left our orange bird looks quite different now lolz ;)&lt;br /&gt;
&lt;br /&gt;
We moved the layout into a &lt;code&gt;script&lt;/code&gt; tag in our markup and gave it an identifier. The template has special markers &lt;code&gt;&amp;lt;%= expression %&amp;gt;&lt;/code&gt; to denote where it should evaluate data passed to it. You can also use the &lt;code&gt;&amp;lt;% statements %&amp;gt;&lt;/code&gt; symbols to put whatever JavaScript you want in there (think loops, branching, etc...)!  &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=underscore-before.html"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-g0AGryuJAFE/UWB-rxhthnI/AAAAAAAAZ1g/o57Bn_sUSx8/s1600/with_great_power_comes_great_responsibility_by_itomibhaa-d4lajvl.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="320" src="http://3.bp.blogspot.com/-g0AGryuJAFE/UWB-rxhthnI/AAAAAAAAZ1g/o57Bn_sUSx8/s320/with_great_power_comes_great_responsibility_by_itomibhaa-d4lajvl.png" width="225" /&gt;&lt;/a&gt;&lt;/div&gt;You can play around with the above code snippets in &lt;a _blank="" href="http://jsfiddle.net/wkH3k/" target=""&gt;jsFiddle&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
As Uncle Ben said, "With great power, comes great responsibility."&lt;br /&gt;
&lt;br /&gt;
Being able to put whatever code you want in your template isn't the best idea in the world. By putting the date manipulation logic in the template it makes it really tough to Unit Test that piece of code. Just imagine if we started cluttering our template with more and more code blocks that like. If you go this route, then you aren't really solving the original problem at hand which was combining presentation and logic. &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Take 2&lt;/h3&gt;&lt;br /&gt;
The following is another take at using Underscore, but this time doing the data manipulation before. The downside is that I'm using the &lt;code&gt;_.map()&lt;/code&gt; method and converting each date property to the relative version. There is some overhead in me having to loop over the data before handing it off to the templating engine. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=underscore-after.js"&gt;&lt;/script&gt;&lt;br /&gt;
We were able to remove the date logic in the following template since we did that work above in the JavaScript before calling the template to do its work. The result is better than what we started with, but it could be better. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=underscore-after.html"&gt;&lt;/script&gt;&lt;br /&gt;
You can play around with the above code snippets in &lt;a _blank="" href="http://jsfiddle.net/auBUX/" target=""&gt;jsFiddle&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Why use Underscore.js?&lt;/h3&gt;&lt;br /&gt;
&lt;div style="width: 100%;"&gt;&lt;div style="float: left; width: 50%;"&gt;&lt;h4&gt;Pros&lt;/h4&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;You can stick arbitrary JavaScript in the template&lt;/li&gt;
&lt;li&gt;It is very small&lt;/li&gt;
&lt;li&gt;If you are already using Backbone.js then you have it&lt;/li&gt;
&lt;li&gt;If you are already using Underscore.js then you have it&lt;/li&gt;
&lt;li&gt;You can Compile the Templates&lt;/li&gt;
&lt;li&gt;Can Run on the Client and the Server&lt;/li&gt;
&lt;li&gt;Can you think of others?&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;div style="float: right; width: 50%;"&gt;&lt;h4&gt;Cons&lt;/h4&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;You can stick arbitrary JavaScript in the template&lt;/li&gt;
&lt;li&gt;Doesn't have the concept of &lt;code&gt;this&lt;/code&gt; in templates&lt;/li&gt;
&lt;li&gt;Can you think of others?&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;Handlebars.js&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ads8NbsvuFk/UWBqEezk1kI/AAAAAAAAZ1Q/N-LZmHnRDzM/s1600/handlebars_logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="195" src="http://1.bp.blogspot.com/-ads8NbsvuFk/UWBqEezk1kI/AAAAAAAAZ1Q/N-LZmHnRDzM/s320/handlebars_logo.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;Overall I tend to prefer the Handlebar.js over Underscore's template engine. Handlebars encourages you to separate your presenting from your logic, it is faster, and it provides a mechanism to precompile your templates that we will look at here in a bit.&lt;br /&gt;
&lt;br /&gt;
First let's take another look at the problem we have been addressing throughout this post. The following code uses Handlebars to template the solution. The code is still pretty clean as was the previous version. You'll notice that I am defining a custom helper called &lt;code&gt;fromNow&lt;/code&gt; that can be used in the template.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=handlebars.js"&gt;&lt;/script&gt;&lt;br /&gt;
And now for the templating syntax below. The syntax feels much more terse to me compared to Underscore, which I like. Inside the template we are using the &lt;code&gt;fromNow&lt;/code&gt; template helper to convert the time. This is nice so we don't have to map over our array beforehand like we did with Underscore or put the logic in the template itself.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=handlebars.html"&gt;&lt;/script&gt;&lt;br /&gt;
You can play around with the above code snippets in &lt;a _blank="" href="http://jsfiddle.net/UeWHb/" target=""&gt;jsFiddle&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Precompiling Your Templates&lt;/h3&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-0c96euSzkrg/UWB2qOZsEHI/AAAAAAAAZ1Y/__iqDNw7IwE/s1600/batman-unicorn-dolphins.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-0c96euSzkrg/UWB2qOZsEHI/AAAAAAAAZ1Y/__iqDNw7IwE/s320/batman-unicorn-dolphins.jpg" width="249" /&gt;&lt;/a&gt;I briefly mentioned above that one of the things I liked was that you can precompile your templates. What does that even mean!?! Well, with both Underscore and Handlebars you need to compile your template before you use it (technically you can do it in one step with Underscore, but it still has to be done under the covers). Compiling a template is good to do if you plan on using it more than once or if you just want it done before you need it. &lt;br /&gt;
&lt;br /&gt;
However, with Handlebars you can go one step further and compile the template on the server and include that on the front-end. This means that you can reduce that amount of work needed on the front-end AND there is a trimmed down version of the handlebars runtime that you can use that has only the parts necessary needed to execute a template (not compile it)!&lt;br /&gt;
&lt;br /&gt;
How cool is that? If your answer was "It's just about as cool as Batman riding on a Rainbow Unicorn alongside dolphins!", then you were right! Congratulations ;)&lt;br /&gt;
&lt;br /&gt;
So how does that work exactly? Well, first you install Handlebars on your server using Node...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=install-handlebars.sh"&gt;&lt;/script&gt;&lt;br /&gt;
Then you take your template contents (what is between the &lt;code&gt;script&lt;/code&gt; tags) and save it to a file. In our case let's save it as &lt;code&gt;tweets.tmpl&lt;/code&gt;. How run the &lt;code&gt;handlebars&lt;/code&gt; precompiler against your template file.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=precompile-handlebars.sh"&gt;&lt;/script&gt;&lt;br /&gt;
Once all of that is done you have a precompiled version of your template that you can now include on your front-end application like the following...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=handlebars-precompile-include.html"&gt;&lt;/script&gt;&lt;br /&gt;
Now that your template is available on the page you can access it by asking &lt;code&gt;Handlebars&lt;/code&gt; for the precompiled version and you are all set to start using it!&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5324961.js?file=handlebars-precompile-include.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Why use Handlebars.js?&lt;/h3&gt;&lt;br /&gt;
&lt;div style="width: 100%;"&gt;&lt;div style="float: left; width: 50%;"&gt;&lt;h4&gt;Pros&lt;/h4&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Its a Logic-less Template Engine&lt;/li&gt;
&lt;li&gt;You can Precompile Templates on the Server&lt;/li&gt;
&lt;li&gt;Supports Helper methods&lt;/li&gt;
&lt;li&gt;Can Run on the Client and the Server&lt;/li&gt;
&lt;li&gt;Supports the concept of &lt;code&gt;this&lt;/code&gt; in templates&lt;/li&gt;
&lt;li&gt;It iss a superset of Mustache.js&lt;/li&gt;
&lt;li&gt;Can you think of others?&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;div style="float: right; width: 50%;"&gt;&lt;h4&gt;Cons&lt;/h4&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Can you think of any?&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;What About Other Templating Engines?&lt;/h2&gt;&lt;br /&gt;
That is a great question. Maybe your needs are different than mine or maybe you just don't like one of the engines that I've mentioned. If that is the case then you should check out a great tool created by Garann Means (&lt;a href="http://twitter.com/garannm" target="_blank"&gt;@garannm&lt;/a&gt;) called the &lt;a href="http://garann.github.io/template-chooser/" target="_blank"&gt;Template Chooser&lt;/a&gt;. The chooser will ask you a set of questions that will help determine which templating engine is right for your needs. The following is an example of what the chooser looks like...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-n_FEUjxHn_s/UWBZDHPelKI/AAAAAAAAZ04/67e-eXyZ3K4/s1600/template-chooser.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="408" src="http://2.bp.blogspot.com/-n_FEUjxHn_s/UWBZDHPelKI/AAAAAAAAZ04/67e-eXyZ3K4/s640/template-chooser.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;Additional Resources&lt;/h2&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/introduction-to-handlebars/" target="_blank"&gt;An Introduction to Handlebars&lt;/a&gt; by Gabriel Manricks (&lt;a href="http://twitter.com/GabrielManricks" target="_blank"&gt;@GabrielManricks&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/best-practices-when-working-with-javascript-templates/" target="_blank"&gt;Best Practices When Working With JavaScript Templates&lt;/a&gt; by Andrew Burgess (&lt;a href="http://twitter.com/andrew8088" target="_blank"&gt;@andrew8088&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://css.dzone.com/articles/demo-handlebars-and-why-you" target="_blank"&gt;Demo of Handlebars, and Why You Should Consider a Templating Engine&lt;/a&gt; Raymond Camden (&lt;a href="http://twitter.com/cfjedimaster" target="_blank"&gt;@cfjedimaster&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.html5rocks.com/en/tutorials/webcomponents/template/" target="_blank"&gt;HTML's New Template Tag: Standardizing Client-Side Templating &lt;/a&gt; by Eric Bidelman (&lt;a href="http://twitter.com/ebidel" target="_blank"&gt;@ebidel&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Orange Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/U3qVB/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-PMJoeP3U0iU/UWCIzvwEXlI/AAAAAAAAZ1w/kJjp8Fd0ouQ/s1600/4-6-2013+3-41-27+PM.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Mixing markup in code can lead to some nasty looking code that is cumbersome, monotonous, and difficult to maintain. Being able to split these apart is a great benefit for developers to simplify their code and help keep each concern in its place. Thankfully libraries like Underscore and Handlebars help us out by providing a clean way to describe presentation apart from logic. THere is a lot of freedom depending on what library you use, but I'd encourage you to look around and find one that works for you. The answer to that may be not to use one and that is fine. &lt;br /&gt;
&lt;br /&gt;
There are many other front-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/778640207951909205/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-orange-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/778640207951909205?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/778640207951909205?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-orange-bird.html" title="Angry Birds of JavaScript: Orange Bird - Templating" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-EoYTO-3jfeY/UV-WOmhaF3I/AAAAAAAAZ0g/S1oYMzsOg2w/s72-c/angrybirds_620_121112.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEYESXc-fip7ImA9WhBWFE4.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-7738027591275493045</id><published>2013-04-08T00:05:00.000-05:00</published><updated>2013-04-08T09:41:48.956-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-08T09:41:48.956-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Green Bird - Mocking</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/4QG5Q/ http://plnkr.co/edit/syYXSOWx1UWUlbFAd0v9 --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-5PVLpWoGRVc/UV4ySyeL9vI/AAAAAAAAZxk/IlyY8pkqXF0/s1600/Angry_birds_wallpaper_3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="161" src="http://4.bp.blogspot.com/-5PVLpWoGRVc/UV4ySyeL9vI/AAAAAAAAZxk/IlyY8pkqXF0/s400/Angry_birds_wallpaper_3.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-8IQeI6F5-d8/UV4ybFGUw7I/AAAAAAAAZxs/jnudV9GSHpM/s1600/green-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-8IQeI6F5-d8/UV4ybFGUw7I/AAAAAAAAZxs/jnudV9GSHpM/s1600/green-bird.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Bird - RequireJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html" target="_blank"&gt;Black Bird - Backbone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html" target="_blank"&gt;White Bird - Linting&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Green Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the Green Bird that can penetrate all of those hard to reach places and will mock and spy those stealing swine right where it hurts!. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
For the most part the birds are all front-end web developers only and don't focus on the back-end much at all. As a result the birds have a symbiotic relationship with the Water Buffalo. The Buffalo write the back-end of the application and the birds develop the front-end. The problem with this arrangement is that while the back-end is being developed the birds are left twiddling their feathers until the Buffalo are finished. However, once the back-end is done the pressure is on the birds to deliver while the Buffalo sit idle by the watering hole in the shade. Thankfully, a while back, a Green Bird proposed the idea of mocking the back-end services so they could make progress on the front-end while they waited for the Buffalo to finish their work! The Green Bird introduced a couple of handy libraries to make mocking a much easier process. &lt;br /&gt;
&lt;br /&gt;
However, during a recent invasion the pigs stole the birds' mocking libraries! As a result, one of the Green Birds has been tasked to reclaim what has been stolen. He will use his overwhelming power of trickery to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;The Twitter Application&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ZbrUacc6Jn8/UV8-TkAbAaI/AAAAAAAAZz4/HiqK67BDc14/s1600/373892_3410142_lz.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="171" src="http://1.bp.blogspot.com/-ZbrUacc6Jn8/UV8-TkAbAaI/AAAAAAAAZz4/HiqK67BDc14/s320/373892_3410142_lz.jpg" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;We are going to take a look at a simple Twitter application that gets the tweets from a specific username. Why Twitter? Well, the Angry Birds have a special relationship with Twitter, especially the Blue Bird ;)&lt;br /&gt;
&lt;br /&gt;
The following application grabs data from Twitter using JSONP. I thought about using Backbone.js to write the little application, but thought that might be overkill to introduce the mocking concept. You will also notice I am not using a templating engine and that is on purpose. Another Angry Bird will be introducing that concept ;)&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5321634.js?file=twitter.js"&gt;&lt;/script&gt;&lt;br /&gt;
The above code snippet is running in the below embedded jsFiddle. Feel free to run the code and launch the editor to play around with it.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Twitter Application using api.twitter.com&lt;/h3&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="300" src="http://jsfiddle.net/KXr8U/1/embedded/result,html" width="100%"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
The data that comes back from Twitter looks something like the following screenshot...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-7pLXYbHr5Lc/UV9FEJXJVPI/AAAAAAAAZ0A/81W9-kKIt94/s1600/twitter-raw.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="458" src="http://2.bp.blogspot.com/-7pLXYbHr5Lc/UV9FEJXJVPI/AAAAAAAAZ0A/81W9-kKIt94/s640/twitter-raw.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;Mocking Static Data&lt;/h2&gt;&lt;br /&gt;
What if Twitter goes down, is unstable, or you just want to test your application without having internet access? This is where being able to mock the back-end service can be really helpful. Thankfully we can use a jQuery library called Mockjax. All you need to do is call &lt;code&gt;$.mockjax&lt;/code&gt; and provide a URL that you want to listen for and a response that you want to be returned. The following is an example of mocking the call to api.twitter.com and passing back some static data.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5321634.js?file=requests-mocked-static.js"&gt;&lt;/script&gt;&lt;br /&gt;
Not only is this pretty cool and can be helpful for developing the front-end independent from the back-end, but it also very handy when writing Unit Tests that use Ajax.&lt;br /&gt;
&lt;br /&gt;
The above code snippet is running in the below embedded jsFiddle. Feel free to run the code and launch the editor to play around with it.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Twitter Application using Mockjax&lt;/h3&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="300" src="http://jsfiddle.net/ufqPC/1/embedded/result,html" width="100%"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
The data that comes back from Mockjax looks something like the following screenshot...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-rgQyF9j9VbA/UV9FPdMawYI/AAAAAAAAZ0I/-ESPFAkZwoY/s1600/twitter-mock-static.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="264" src="http://4.bp.blogspot.com/-rgQyF9j9VbA/UV9FPdMawYI/AAAAAAAAZ0I/-ESPFAkZwoY/s640/twitter-mock-static.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;Mocking Dynamic Semi-Random Data&lt;/h2&gt;&lt;br /&gt;
One of the downsides of this technique is that generally I am pretty unimaginative and lazy when making static data examples. I typically end up have the same object and just increment some of the values by 1 or something. That is fine and all, but it is a nuisance, it takes time, and it doesn't really give you an idea of what the UI could look like. Thankfully there is another nice library for that called mockJSON. You provide a template of what you want your data to look like and then you give it some metadata about what types of fields you want, how many, etc... The following is how I rewrote the previous example, but will randomly generate anywhere from 5 to 10 twitter objects to be displayed.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5321634.js?file=requests-mocked-dynamic.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
The above code snippet is running in the below embedded jsFiddle. Feel free to run the code and launch the editor to play around with it.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Twitter Application using Mockjax &amp;amp; mockJSON&lt;/h3&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="300" src="http://jsfiddle.net/cHS9q/1/embedded/result,html" width="100%"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
The data that comes back from Mockjax with mockJSON looks something like the following screenshot...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-mvenxQzawwU/UV9FW2MqpUI/AAAAAAAAZ0Q/6TA0UmXP-9w/s1600/twitter-mock-dynamic.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="264" src="http://4.bp.blogspot.com/-mvenxQzawwU/UV9FW2MqpUI/AAAAAAAAZ0Q/6TA0UmXP-9w/s640/twitter-mock-dynamic.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Green Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/4QG5Q/27/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="396" src="http://3.bp.blogspot.com/-eLUAASpDUy0/UV0NIExF6RI/AAAAAAAAZwA/uCKAm54p5W4/s640/Screenshot+on+4.4.2013+at+12.14.59+AM.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
It can be difficult to develop both the front-end and back-end independently. Thankfully there are some techniques and libraries today that can enable the front-end to develop and prototype separate from the back-end progress. The mocking techniqiue with static data can also be helpful when Unit Testing your code as well.&lt;br /&gt;
&lt;br /&gt;
There are many other front-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/7738027591275493045/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/7738027591275493045?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/7738027591275493045?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html" title="Angry Birds of JavaScript: Green Bird - Mocking" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-5PVLpWoGRVc/UV4ySyeL9vI/AAAAAAAAZxk/IlyY8pkqXF0/s72-c/Angry_birds_wallpaper_3.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUMGRXwyfSp7ImA9WhBWEEg.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-9169041367629258596</id><published>2013-04-04T00:19:00.001-05:00</published><updated>2013-04-04T00:30:24.295-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-04T00:30:24.295-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: White Bird - Linting</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/4QG5Q/ http://plnkr.co/edit/syYXSOWx1UWUlbFAd0v9 --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-hbs_feLNzNE/UVx7DKXG-cI/AAAAAAAAZug/vDk6cFJ7Jgk/s1600/angry_birds_wall_decal_by_graphicwolf-d4fwzrc.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="243" src="http://4.bp.blogspot.com/-hbs_feLNzNE/UVx7DKXG-cI/AAAAAAAAZug/vDk6cFJ7Jgk/s400/angry_birds_wall_decal_by_graphicwolf-d4fwzrc.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-c3JawpCl3ys/UVx7L_dMWxI/AAAAAAAAZuo/YEClyACJaZg/s1600/white-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-c3JawpCl3ys/UVx7L_dMWxI/AAAAAAAAZuo/YEClyACJaZg/s1600/white-bird.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Bird - RequireJS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Black Bird - Backbone&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;White Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the White Bird who appears to be seemingly harmless, but when it pulls out it's strict coding style and bursts of quality checks the hogs are sure to squeal. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
The birds all learned how to program in a slightly different way. Some birds were self-taught and some birds went to college for computer science. Even among those groups there were a wide range of experiences and talent. When the birds got together to build their first large application it was a huge disaster. Each bird thought their coding standard was the "right way" and it started to become an issue. One day a wise White Bird came along and suggested that they come up with a common set of coding practices to follow. In addition, the White Bird introduced a few tools to help them conform to a standard and to help find issues and concerns early before they became a huge issue later.&lt;br /&gt;
&lt;br /&gt;
However, during a recent invasion the pigs stole the birds' coding standards document and their code quality tools! As a result, one of the White Birds has been tasked to reclaim what has been stolen. He will use his overwhelming power of quality to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;JavaScript Coding Standards&lt;/h2&gt;&lt;br /&gt;
There are many coding standards out there to choose from. The most important thing is that you pick one and stick to it. If you are working with a team, they should also agree on some standard. If you can't find a standard you exactly agree on, then find one that is close and make some exceptions.&lt;br /&gt;
&lt;br /&gt;
By doing so you'll find that...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;A developer will be able to make sense of other code more quickly&lt;/li&gt;
&lt;li&gt;Merges in your code repository won't be as awful&lt;/li&gt;
&lt;li&gt;Having a standard will actually reduce defects&lt;/li&gt;
&lt;li&gt;The codebase will feel more unified&lt;/li&gt;
&lt;li&gt;Disagreements about who is "right" will lessen&lt;/li&gt;
&lt;li&gt;... insert your benefit here ...&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Here are some of the coding standards that I am aware of...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Douglas Crockford's &lt;a href="http://javascript.crockford.com/code.html" target="_blank"&gt;Code Conventions for the JavaScript Programming Language&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Rich Waldron's (&lt;a href="http://twitter.com/rwaldron" target="_blank"&gt;@rwaldron&lt;/a&gt;) &lt;a href="https://github.com/rwldrn/idiomatic.js" target="_blank"&gt;Idiomatic.js - Principles of Writing Consistent, Idiomatic JavaScript&lt;/a&gt; ← Recommended&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;jQuery's &lt;a href="http://contribute.jquery.org/style-guide/js/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DJQuery_Core_Style_Guidelines%26redirect%3Dno" target="_blank"&gt;JavaScript Style Guide &lt;/a&gt; ← Recommended&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Google's &lt;a href="http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml" target="_blank"&gt;JavaScript Style Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Addy Osmani (&lt;a href="http://twitter.com/addyosmani" target="_blank"&gt;@addyosmani&lt;/a&gt;) has a nice post entitled &lt;a href="http://addyosmani.com/blog/javascript-style-guides-and-beautifiers/" target="_blank"&gt;JavaScript Style Guides And Beautifiers&lt;/a&gt; that covers some of these styles in depth with examples showing how to abide by the standards recommended. &lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;JavaScript Linting&lt;/h2&gt;&lt;br /&gt;
A linter is a tool that helps find errors and possible issues with your code. In many cases it can help enforce whatever coding standard you chose from the above list.&lt;br /&gt;
&lt;br /&gt;
There are actually several JavaScript linters out there, but the one I like the best is &lt;a href="http://jshint.com/" target="_blank"&gt;JSHint&lt;/a&gt; created by Anton Kovalyov (&lt;a href="http://twitter.com/valueof"&gt;@valueof&lt;/a&gt;). It grew out of a community effort to fork the popular JSLint library written by Douglas Crockford. I've enjoyed watching the project grow and see bugs and new features being added. JSHint has a lot of options that you can choose to opt-in or opt-out of which enables a team to figure out what works best for them. &lt;br /&gt;
&lt;br /&gt;
Some of the standard checks that JSHint can verify include...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;The use of &lt;code&gt;===&lt;/code&gt; instead of &lt;code&gt;==&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Using variables that aren't defined&lt;/li&gt;
&lt;li&gt;Declaring variables that are never used&lt;/li&gt;
&lt;li&gt;Declaring functions inside of loops&lt;/li&gt;
&lt;li&gt;And lots more...&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
For a full list of options see the &lt;a href="http://jshint.com/docs/" target="_blank"&gt;JSHint Docs&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the more recent additions that I've really enjoyed include:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;code&gt;maxcomplexity&lt;/code&gt; - Maximum cyclomatic complexity (see following Wikipedia quote)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maxstatements&lt;/code&gt; - Maximum number of statements allowed in a function&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maxparams&lt;/code&gt; - Maximum number of parameter allowed in a function&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maxdepth&lt;/code&gt; - Maximum depth allowed in a function&lt;/li&gt;
&lt;li&gt;&lt;code&gt;maxlen&lt;/code&gt; - Maximum length of line in code&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;blockquote&gt;"The cyclomatic complexity of a section of source code is the count of the number of linearly independent paths through the source code." --&lt;a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity"&gt;http://en.wikipedia.org/wiki/Cyclomatic_complexity&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5307478.js?file=jshint.js"&gt;&lt;/script&gt;&lt;br /&gt;
The following errors are generated by JSHint after running it against the above code snippet.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Jj5KYftluoQ/UVz04mayIXI/AAAAAAAAZvQ/P9diYW0g8UE/s1600/4-3-2013+10-33-12+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="352" src="http://1.bp.blogspot.com/-Jj5KYftluoQ/UVz04mayIXI/AAAAAAAAZvQ/P9diYW0g8UE/s640/4-3-2013+10-33-12+PM.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Thankfully you don't have to run JSHint from the website every time to check your code. There are several ways to integrate it into your code editor of choice:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;VIM Plugin (&lt;a href="https://github.com/walm/jshint.vim" target="_blank"&gt;jshint.vim&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Sublime Text 2 Extension (&lt;a href="https://github.com/Kronuz/SublimeLinter" target="_blank"&gt;Sublime Linter&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;TextMate Bundle (&lt;a href="http://fgnass.posterous.com/jslint-in-textmate" target="_blank"&gt;JSHint TextMate Bundle&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Visual Studio &lt;a href="http://vswebessentials.com/" target="_blank"&gt;Web Essentials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Eclipse IDE (&lt;a href="http://github.eclipsesource.com/jshint-eclipse/" target="_blank"&gt;JSHint Integration&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;blockquote&gt;In the Mighty Eagle post we'll talk about another way to use the JSHint from the command line and automatically.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h2&gt;JavaScript Analysis&lt;/h2&gt;&lt;br /&gt;
Code linting is great, but sometimes it is nice to get a high level overview of your codebase and then be able to drill down and analyze small portions of your application.&lt;br /&gt;
&lt;br /&gt;
Thankfully there is a tool called &lt;a href="https://github.com/jsoverson/plato" target="_blank"&gt;Plato&lt;/a&gt; that will analyse your code and provide a visual report where you can view the complexity of your application. The tool runs in Node and you can install it using &lt;code&gt;npm install plato -g&lt;/code&gt;. &lt;br /&gt;
&lt;br /&gt;
Once installed you can run the tool on the command line by &lt;code&gt;plato -r -d report myDirectory&lt;/code&gt;, which will recursively analyse the code in the &lt;code&gt;myDirectory&lt;/code&gt; folder and export the results to the &lt;code&gt;report&lt;/code&gt; folder.&lt;br /&gt;
&lt;br /&gt;
If you were to run the report on the jQuery source code it would look much like the following report. As you can see, the average number of lines is decreasing over time, which is good. The maintainability is decent and then a breakdown of the maintainability of each JavaScript file is listed in a bar chart. Further down in the report there are a bar charts for Lines of code broken per file, Estimated errors per file, and also JSLint errors per file. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-WfsE5xqGhjc/UV0Fi3Kd9vI/AAAAAAAAZvg/IWnkno7LaK8/s1600/jquery-top-level.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="548" src="http://2.bp.blogspot.com/-WfsE5xqGhjc/UV0Fi3Kd9vI/AAAAAAAAZvg/IWnkno7LaK8/s640/jquery-top-level.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
If you drill into one of the particular files from above you'll see a view that looks like the following. The nice part about this report is that it breaks down each function into complexity and lines of code in a way that is easy to grasp. You can quickly jump to various parts of the file to review the concerns the tool is identifying.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-GHHmjChHTdo/UV0Fn9yzTwI/AAAAAAAAZvo/qMwHcRxb3p8/s1600/jquery-drill-complexity.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="324" src="http://2.bp.blogspot.com/-GHHmjChHTdo/UV0Fn9yzTwI/AAAAAAAAZvo/qMwHcRxb3p8/s640/jquery-drill-complexity.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
You can view the above &lt;a href="http://jsoverson.github.com/plato/examples/jquery/" target="_blank"&gt;jQuery Report&lt;/a&gt; from Plato's GitHub repository.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the White Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/4QG5Q/1/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="396" src="http://3.bp.blogspot.com/-eLUAASpDUy0/UV0NIExF6RI/AAAAAAAAZwA/uCKAm54p5W4/s640/Screenshot+on+4.4.2013+at+12.14.59+AM.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Front-end web applications can get complicated quickly. If your developers aren't all on the same page then things can fall apart in a heartbeat, especially on a large project. Having a unified coding standard and implementing some tools to help find issues before they become a problem can really help to make your project a success. &lt;br /&gt;
&lt;br /&gt;
There are many other front-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/9169041367629258596/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/9169041367629258596?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/9169041367629258596?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html" title="Angry Birds of JavaScript: White Bird - Linting" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-hbs_feLNzNE/UVx7DKXG-cI/AAAAAAAAZug/vDk6cFJ7Jgk/s72-c/angry_birds_wall_decal_by_graphicwolf-d4fwzrc.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CkQMQXw_fSp7ImA9WhBWEEw.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-3996829342629290282</id><published>2013-04-03T00:05:00.000-05:00</published><updated>2013-04-03T12:33:00.245-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-03T12:33:00.245-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Backbone" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Black Bird - Backbone</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/4QG5Q/ http://plnkr.co/edit/syYXSOWx1UWUlbFAd0v9 --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-efyDWffod9w/UVpR-LEJYyI/AAAAAAAAZgE/w6UXvXY3u9w/s1600/000001611.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-efyDWffod9w/UVpR-LEJYyI/AAAAAAAAZgE/w6UXvXY3u9w/s200/000001611.jpg" width="154" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-wjhQKJKNuks/UVdeWffTYoI/AAAAAAAAZNY/XpHY_8R3tQs/s1600/black-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-wjhQKJKNuks/UVdeWffTYoI/AAAAAAAAZNY/XpHY_8R3tQs/s1600/black-bird.png" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Bird - RequireJS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Black Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the Black Bird who will use the organized approach of the &lt;a href="http://draft.blogger.com/backbonejs.org" target="_blank"&gt;Backbone.js&lt;/a&gt; bomb to fight these porkers. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
The birds used to write their jQuery code like it was a tangled smorgasbord of worms. They would mix up their views, models, and presenter logic all together in a big interconnected pile of grubs. After a while one of their ancestors, a Black Bird, introduced the Backbone.js library and showed them a different way to think about developing front-end web applications. However, during a recent invasion the pigs stole Backbone.js from the birds and carried it back to their filthy sty.&lt;br /&gt;
&lt;br /&gt;
One of the black birds has been tasked to reclaim what has been stolen. He will use his explosive power of organization to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Tangled Smorgasbord of Worms&lt;/h2&gt;&lt;br /&gt;
Let's take a look again at the following application that the &lt;a href="http://draft.blogger.com/blogger.g?blogID=30404818"&gt;Blue Bird&lt;/a&gt; dealt with in a previous attack. Instead of adding messages to untangle the mess we are going to introduce how using Backbone.js can help us out. Here is the running application below...&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;It appears &lt;a href="http://plnkr.co/"&gt;Plunker&lt;/a&gt; is not embedding correctly at the moment. The application is a simple Netflix search interface that will show the results from Netflix. If Plunker doesn't start working soon I will move the demo somewhere else. Sorry for the inconvenience.&lt;/blockquote&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" src="http://embed.plnkr.co/td1ZTtptDT0RIxc7VIgM" style="height: 300px; width: 100%;"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
And to refresh your memory, here is the supporting code used for the above web application. You should notice that a lot of concerns are all being mixed together (DOM events, Modifying the View, AJAX Communication, etc...)&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=jquery-worms.js"&gt;&lt;/script&gt;&lt;br /&gt;
Do you see the problem? It is so tempting to write code like the above, but I hope you see that it can be a bear to work with and maintain. Don't worry, we have all written code just like the above. The good news is that we don't have to continue to write it that way. Let's take a look at what Backbone.js is and how it can help us out in this situation. &lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;There are many other MV* front-end frameworks (Knockout, or AngularJS, EmberJS, &amp; others) that could also bring structure to the above code. I would encourage you to pick a tool that you can be productive with and get comfortable with it.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h2&gt;Backbone.js Basics&lt;/h2&gt;&lt;br /&gt;
Backbone.js has several pieces that can all work together to make a web application. You don't have to use all of these components, but they are available if you choose to use them.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Model - Represents data and logic surrounding it&lt;/li&gt;
&lt;li&gt;Collection - Ordered sets of Models&lt;/li&gt;
&lt;li&gt;View - A module backed by a Model with a render method&lt;/li&gt;
&lt;li&gt;Router - Mechanism to provide linkable, sharable URLs&lt;/li&gt;
&lt;li&gt;Event - Observer Eventing module&lt;/li&gt;
&lt;li&gt;History - Provides the ability to maintain history (back button support)&lt;/li&gt;
&lt;li&gt;Sync - Extendable component providing RESTful communication to the server&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Refactoring the Tightly Coupled Code&lt;/h2&gt;&lt;br /&gt;
Let's take a stab at refactoring the above jQuery mess and use Backbone.js to split out some of the various concerns. &lt;br /&gt;
&lt;br /&gt;
I'm not going to dive into all of the above pieces in this post, but will focus on 3 of the main pieces (Models, Collections, and Views). I'll touch on some of the Sync concerns, but as part of the other topics. I'll have resources listed at the end if you want to dig deeper into any of these topics.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;RequireJS&lt;/h3&gt;&lt;br /&gt;
Before we get into the Models, Collections, and Views I want to show you how we took out all the scripts from the index.html page and used RequireJS to help us out.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;If you've never seen RequireJS before then you might want to check out the previous &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Yellow Angry Bird Post&lt;/a&gt;&lt;/strong&gt; about RequireJS.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h4&gt;main.js&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=main.js"&gt;&lt;/script&gt;&lt;br /&gt;
The above code is defining the paths for jQuery, Underscore, Backbone, Postal, and Bootstrap. We needed to shim Underscore, Backbone, and Bootstrap since they are not defined as AMD modules. &lt;br /&gt;
&lt;br /&gt;
Then the &lt;code&gt;require&lt;/code&gt; function is called to request a set of dependencies before the callback is invoked. At that point, jQuery and all the other views and models will be ready for usage!&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Models&lt;/h3&gt;&lt;br /&gt;
We are going to make 2 models (Search and Movie) to represent the above application. &lt;br /&gt;
&lt;br /&gt;
The following Search Model is really simple and its main job is to respond when the &lt;code&gt;term&lt;/code&gt; property has changed. We are using Backbone's events (Observer Events) to listen to changes on the model and then propagating the message to Postal.js (Mediated Events). For more information about those terms and how they are different you can reference the &lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Angry Bird Post&lt;/a&gt; about events.  &lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;search.js&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=search.js"&gt;&lt;/script&gt;&lt;br /&gt;
The following Movie Model doesn't have a lot going on as well. It's main purpose is to parse the data returned from the server and map the results to something a little more manageable. In this case we are only concerned with the &lt;code&gt;releaseYear&lt;/code&gt;, &lt;code&gt;rating&lt;/code&gt;, and &lt;code&gt;name&lt;/code&gt; properties.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;movie.js&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=movie.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Collections&lt;/h3&gt;&lt;br /&gt;
As we described above, collections are just a set of models. The following code is just a set of Movie models. The collection is where you define where to get the list of models from the server. The back-end for this application is Netflix and their endpoint is a little complex so we are using a function to dynamically build that URL. We also defined a &lt;code&gt;parse&lt;/code&gt; method to get directly to the array of contents that will be mapped to &lt;code&gt;Movie&lt;/code&gt; models. Since this AJAX call will be using JSONP we also needed to override the &lt;code&gt;sync&lt;/code&gt; method and provide some additional options.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;movies.js&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=movies.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Views&lt;/h3&gt;&lt;br /&gt;
I see the View as more of a Presenter than the typical MVC View you might normally think of. Anyway, We have 2 views in this application that we will briefly look at.&lt;br /&gt;
&lt;br /&gt;
The following &lt;code&gt;SearchView&lt;/code&gt; handles the interactions with the DOM and the Model. The &lt;code&gt;events&lt;/code&gt; property primarily is used to listen to DOM events and in this case is watching for clicks on the button or previous search links. Changes to these elements will be stored in the model as &lt;code&gt;term&lt;/code&gt;. The &lt;code&gt;initialize&lt;/code&gt; method sets up some events listening for changes in the &lt;code&gt;term&lt;/code&gt; property. If &lt;code&gt;term&lt;/code&gt; changes, then portions of the UI will change accordingly.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;search-view.js&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=search-view.js"&gt;&lt;/script&gt;&lt;br /&gt;
The &lt;code&gt;MovieView&lt;/code&gt; below is a little different than the above view. The first thing to point out is the weird &lt;code&gt;text!movie-template.html&lt;/code&gt;. I am using the &lt;code&gt;text.js&lt;/code&gt; plugin for RequireJS that let's us pull text resources as part of the dependency chain. This is really helpful for markup files used when using a templating engine or possibly a CSS file that is associated with a particular widget. Inside of the &lt;code&gt;initialize&lt;/code&gt; method we are subscribing to a change in the term and then asking the collection to &lt;code&gt;fetch&lt;/code&gt; the information from the server. The &lt;code&gt;render&lt;/code&gt; method gets called after the data is retrieved from the server and we use Underscore to template the results to the DOM.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;movie-view.js&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=movie-view.js"&gt;&lt;/script&gt;&lt;br /&gt;
The following is the template file in case you were wondering. I'm using Underscore's templating engine which is similar to John Resig's micro-templating implementation that he wrote years ago. There are other templating libraries available, but I used this one because it comes with Underscore which is a prerequisite for Backbone. If I needed something more featured I would have used Handlebars instead, but that is a story for another Angry Bird ;)&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;movie-template.html&lt;/h4&gt;&lt;script src="https://gist.github.com/elijahmanor/5283260.js?file=movie-template.html"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Additional Resources&lt;/h2&gt;&lt;br /&gt;
I only scratched the surface on all the things you can do with Backbone.js. If you are interesting in learning more about these concepts you may want to look at some of the following resources. &lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;The following resources were taken from the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/01/beginner-html5-javascript-jquery.html" target="_blank"&gt;Beginner HTML5, JavaScript, jQuery, Backbone, and CSS3 Resources&lt;/a&gt;&lt;/strong&gt; blog post.&lt;/blockquote&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://backbonejs.org/"&gt;Backbone.js API&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://backbonejs.org/docs/backbone.html"&gt;Annotated Backbone.js Code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/documentcloud/backbone/wiki/Extensions,-Plugins,-Resources"&gt;Backbone Extensions, Plugins, &amp;amp; Resources&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tbranyen/backbone-boilerplate"&gt;Backbone Boilerplate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/addyosmani/backbone-fundamentals"&gt;Backbone Fundamentals eBook&lt;/a&gt; by Addy Osmani (&lt;a href="http://twitter.com/addyosmani"&gt;@addyosmani&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://peepcode.com/products/backbone-js"&gt;Peep Code: Backbone.js Video Series&lt;/a&gt; by Geoffery Grosenbach (&lt;a href="http://twitter.com/topfunky"&gt;@topfunky&lt;/a&gt;) and David Goodlad (&lt;a href="http://twitter.com/dgoodlad"&gt;@dgoodlad&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://pragprog.com/screencasts/v-dback/hands-on-backbone-js"&gt;The Pragmatic Bookshelf: Hands-on Backbone.js&lt;/a&gt; by Derick Bailey (&lt;a href="http://twitter.com/derickbailey"&gt;@derickbailey&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://backbonescreencasts.com/"&gt;Backbone.js Screencasts&lt;/a&gt; by Joey Beninghove&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.pluralsight.com/training/Courses/TableOfContents/backbone-fundamentals"&gt;Pluralsight: Backbone.js Fundamentals&lt;/a&gt; by Liam McLennan (&lt;a href="http://twitter.com/liammclennan"&gt;@liammclennan&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://codular.com/starting-with-backbone"&gt;The Skinny on BackboneJS&lt;/a&gt; by Ben Howdle (&lt;a href="http://twitter.com/benhowdle"&gt;@benhowdle&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;&lt;a href="http://backbonetutorials.com/"&gt;Backbone Tutorials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tag/backbone/"&gt;Backbone.js Tutorials&lt;/a&gt; via Nettuts&lt;/li&gt;
&lt;li&gt;&lt;a href="http://javascriptplayground.com/blog/category/backbonejs"&gt;Exploring Backbone.js Series&lt;/a&gt; by Jack Franklin (&lt;a href="http://twitter.com/jack_franklin"&gt;@jack_franklin&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Black Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-QBX6E-gJmzE/UVuGtHDEmMI/AAAAAAAAZuM/xXbC6KMc3OU/s1600/black-brid-game.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-QBX6E-gJmzE/UVuGtHDEmMI/AAAAAAAAZuM/xXbC6KMc3OU/s1600/black-brid-game.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Front-end web applications can get complicated quickly. Before you know it you have a pile of interconnected mess if you are not careful. Thankfully Backbone.js provides components to help you split out your application into consumable pieces that each have their own purpose. Thank you Black Bird for returning Backbone back to the birds. They will be able to rest easier knowing things are organized and in their proper place.&lt;br /&gt;
&lt;br /&gt;
There are many other front-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/3996829342629290282/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3996829342629290282?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3996829342629290282?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html" title="Angry Birds of JavaScript: Black Bird - Backbone" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-efyDWffod9w/UVpR-LEJYyI/AAAAAAAAZgE/w6UXvXY3u9w/s72-c/000001611.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0EERHs4eCp7ImA9WhBXGEk.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-6104468172640378191</id><published>2013-04-01T00:05:00.000-05:00</published><updated>2013-04-01T15:53:25.530-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-01T15:53:25.530-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Yellow Bird - RequireJS</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Yellow Bird - RequireJS http://jsfiddle.net/LrFVp/14/ http://jsfiddle.net/LrFVp/20/ --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-6p5Xgjlsmhk/UVZlEo_QOKI/AAAAAAAAY9k/BBXhjrfp42U/s1600/Angry-Birds-Logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="212" src="http://4.bp.blogspot.com/-6p5Xgjlsmhk/UVZlEo_QOKI/AAAAAAAAY9k/BBXhjrfp42U/s320/Angry-Birds-Logo.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt;&lt;/strong&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Blue Bird - Events&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-eBq1DHq7P64/UVZlP7q4zMI/AAAAAAAAY9s/g5Ii1ZrLIbs/s1600/yellow-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-eBq1DHq7P64/UVZlP7q4zMI/AAAAAAAAY9s/g5Ii1ZrLIbs/s1600/yellow-bird.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Yellow Bird Attacks&lt;/h3&gt;&lt;br /&gt;
In this post we will take a look at the Yellow Bird who comes with a &lt;a href="http://requirejs.org/" target="_blank"&gt;RequireJS&lt;/a&gt; speed booster and dynamically injects scripts against those pesky swine. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
The birds used to manually add script tags to their HTML files. At first this wasn't an issue, but when their application started to grow larger and more complex it started to become difficult for them to organize their code, figure out dependencies, and determine a strategy for optimizing performance. Thankfully they were introduced to the &lt;a href="http://requirejs.org/" target="_blank"&gt;RequireJS&lt;/a&gt; library which provided them a way to manage their code into modules, load their scripts asynchronously, manage their dependencies, and provide an easy way to optimize. Unfortunately the pigs, during a recent invasion, stole the RequireJS library from the birds.&lt;br /&gt;
&lt;br /&gt;
One of the yellow birds has been tasked to reclaim what has been stolen. He will use the optimization power of speed to help destroy the pigs in order to take back what is theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Broken Application&lt;/h2&gt;&lt;br /&gt;
Let's first start with a simple little web page that contains just a few scripts. You'll notice that I'm loading 3 popular libraries (jQuery, Underscore, and Postal) and some custom code at the end.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=broken-dependency.html"&gt;&lt;/script&gt;&lt;br /&gt;
The above code looks pretty straightforward, but when I end up running the page I get the following error in the dev tool's console...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-ry8ojeQF3OI/UVZosPNPtVI/AAAAAAAAY94/0Catr-PQzbo/s1600/3-29-2013+10-36-11+PM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-ry8ojeQF3OI/UVZosPNPtVI/AAAAAAAAY94/0Catr-PQzbo/s1600/3-29-2013+10-36-11+PM.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Fictitious Internal Dialog: "WHAT!?! I don't see any &lt;code&gt;each&lt;/code&gt; method anywhere. What's up with that? Ohh man, it looks like the exception occurred in postal.min.js somewhere. FOUND A BUG... see if I use that library again. But, wait!?! Ohh, maybe something else is going on here."&lt;br /&gt;
&lt;br /&gt;
So, the real issue isn't a bug in postal.js, the issue is in that postal.js has a dependency on underscore.js. The problem is that underscore should have been loaded before postal.js. Simply rearranging the script tags could easily solve this issue. In the above case the fix was trivial, but imagine how cumbersome this could be once the project starts to get large and requires lots of scripts.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;RequireJS Basics&lt;/h2&gt;&lt;br /&gt;
Before we go and look at how we could fix the above situation using RequireJS, let's first take a high level overview of what the library is doing for us. RequireJS is an Asynchronous Module Loader and the API it provides allows us to define and require modules. Both functions are really easy to understand so let's take a look at them.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;define method&lt;/h3&gt;&lt;br /&gt;
In order to create a module you need a name, a list of dependencies, and a callback function.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=define.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;require method&lt;/h3&gt;&lt;br /&gt;
At some point in your application you will need to use the &lt;code&gt;require&lt;/code&gt; function to kick things off.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=require.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Fixed Application&lt;/h2&gt;&lt;br /&gt;
Using RequireJS I took the above little application and rearranged some things. You should notice that the following markup removes all the script tags except one, which points to the require.js library. RequireJS knows where to start because we add an HTML5 data-main attribute describing where the main script is located.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=requirejs.html"&gt;&lt;/script&gt;&lt;br /&gt;
The main script has a configuration section inside of it where you can assign aliases to existing AMD modules and also shim libraries that were not previously defined. Although jQuery and Postal define themselves as AMD modules we included them in our configuration because they are not located alongside &lt;code&gt;main.js&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
You don't have to include in your config any custom modules you define in your application. You can refer to those by their file path and name.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=main.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Optimize&lt;/h2&gt;&lt;br /&gt;
Our application only has 5 script files in it, but as you know our app will only continue to add additional scripts. So, it would be nice if there was an easy way to combine and minify our scripts for better production performance. The nice thing is that by using RequireJS we have already defined the dependencies of our application.&lt;br /&gt;
&lt;br /&gt;
Thankfully there is a tool called &lt;code&gt;&lt;a href="http://requirejs.org/docs/1.0/docs/optimization.html" target="_blank"&gt;r.js&lt;/a&gt;&lt;/code&gt; that takes this dependency information and uses it to generate a combined and minified script. You can install the tool with the Node Package Manager &lt;code&gt;npm install requirejs&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
You could provide all the command line argument to the tool in the console, but I prefer making a build config file like the following to define all of its settings before I run it. You can find a &lt;a href="https://github.com/jrburke/r.js/blob/master/build/example.build.js"&gt;comprehensive list of settings&lt;/a&gt; from the official GitHub repository.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=build.js"&gt;&lt;/script&gt;&lt;br /&gt;
Once you've defined your &lt;code&gt;build.js&lt;/code&gt; file then you let &lt;code&gt;r.js&lt;/code&gt; know you want to use it. The following command will get you going... &lt;code&gt;r.js -o build.js&lt;/code&gt;. You can see the output of the tool in the output below.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5275285.js?file=optimize.sh"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Additional Resources&lt;/h2&gt;&lt;br /&gt;
I only scratched the surface on all the things you can do with RequireJS and the r.js optimization tool. If you are interesting in learning more about these concepts you may want to look at some of the following resources. &lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Jack Franklin's (&lt;a href="http://twitter.com/jack_franklin" target="_blank"&gt;@jack_franklin&lt;/a&gt;) &lt;a href="http://javascriptplayground.com/blog/2012/07/requirejs-amd-tutorial-introduction"&gt;Introduction to RequireJS&lt;/a&gt; article&lt;/li&gt;
&lt;li&gt;Jeffrey Way's (&lt;a href="http://twitter.com/jeffrey_way" target="_blank"&gt;@jeffrey_way&lt;/a&gt;) &lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/a-requirejs-backbone-and-bower-starter-template/" target="_blank"&gt;A RequireJS, Backbone, and Bower Starter Template&lt;/a&gt; screencast&lt;/li&gt;
&lt;li&gt;Cary Landholt's (&lt;a href="http://twitter.com/carylandholt" target="_blank"&gt;@carylandholt&lt;/a&gt;) &lt;a href="http://www.youtube.com/watch?v=VGlDR1QiV3A"&gt;RequireJS Basics&lt;/a&gt; video&lt;/li&gt;
&lt;li&gt;Jonathan Creamer's (&lt;a href="http://twitter.com/jcreamer898" target="_blank"&gt;@jcreamer898&lt;/a&gt;) &lt;a href="http://tech.pro/tutorial/1156/using-requirejs-in-an-aspnet-mvc-application" target="_blank"&gt;Using Require.js in an ASP.NET MVC application&lt;/a&gt; article&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Yellow Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/Gue8x/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-BvvbLg5ACrI/UVZoyYxCmSI/AAAAAAAAY-E/G7I6uezUKV0/s1600/3-29-2013+11-19-41+PM.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Front-end web applications can get complicated quickly. It is nice to have a way to provide some structure, dependency management, and an easy way to optimize the final result. Thanks to the power of Yellow the birds have regained their trusty RequireJS tool for use in their next application.&lt;br /&gt;
&lt;br /&gt;
There are many other front-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/6104468172640378191/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/6104468172640378191?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/6104468172640378191?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" title="Angry Birds of JavaScript: Yellow Bird - RequireJS" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-6p5Xgjlsmhk/UVZlEo_QOKI/AAAAAAAAY9k/BBXhjrfp42U/s72-c/Angry-Birds-Logo.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;AkUDR34-fyp7ImA9WhBXFEk.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-3219085302078888445</id><published>2013-03-28T00:07:00.001-05:00</published><updated>2013-03-28T00:24:36.057-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-03-28T00:24:36.057-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Blue Bird - Events</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;!-- Blue Bird - Events &amp; Messaging http://jsfiddle.net/LrFVp/14/ http://jsfiddle.net/LrFVp/20/ --&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-6ILPSz-pyp0/UVEnzs_iVfI/AAAAAAAAYVE/yXkm3RWutRs/s1600/angry-birds-game-for-windows-1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://2.bp.blogspot.com/-6ILPSz-pyp0/UVEnzs_iVfI/AAAAAAAAYVE/yXkm3RWutRs/s320/angry-birds-game-for-windows-1.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! &lt;br /&gt;
&lt;br /&gt;
A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
Will the birds be successful in the end? Will they defeat their bacon flavored foe? Let's find out together in another nail biting episode of Angry Birds of JavaScript!&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Check out the &lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" target="_blank"&gt;series introduction post&lt;/a&gt; for a list of all the birds and their attack powers.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Previous Attacks&lt;/h3&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Red Bird - IIFE&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Blue Bird Attack&lt;/h3&gt;&lt;a href="http://3.bp.blogspot.com/-sJcdgjfGHVc/UU_R2M3GqgI/AAAAAAAAYSU/eb2T2_qHjxY/s1600/blue-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-sJcdgjfGHVc/UU_R2M3GqgI/AAAAAAAAYSU/eb2T2_qHjxY/s200/blue-bird.png" width="107" /&gt;&lt;/a&gt;&lt;br /&gt;
In this post we will take a look at the Blue Bird who triggers events and messages that scatter to infiltrate the pig's castle. Slowly, one by one, the birds will take back what it theirs to keep!&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;The birds used to build their web applications with components having hard dependencies on each-other. They eventually started to learn to reduce tight coupling by introducing events and messages. Unfortunately the pigs, during their invasion, stole the birds' observer secrets.&lt;br /&gt;
&lt;br /&gt;
One of the blue birds has been tasked with taking back what has been stolen and restore loose coupling components.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Sample Application&lt;/h2&gt;&lt;br /&gt;
In order to unpack the need for messages we will look at the following web application to search for movies from Netflix. We will uncover how this application was originally coded and then refactor along the way.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" height="350" src="http://jsfiddle.net/LrFVp/14/embedded/result" width="100%"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Tightly Coupled Code&lt;/h2&gt;&lt;br /&gt;
The first version of the above application was coded using the following JavaScript code. Take a look at the code and let it start to sink in for a little bit. It may be painful, but please bar with me for a moment ;)&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5235011.js?file=tightly-coupled.js"&gt;&lt;/script&gt;&lt;br /&gt;
The above code sample is a typical jQuery example that you can find across the internet. The snippet works, but there is a lot of different things happening all in the same place. You can find event handling, data retrieval, and data manipulation all mixed together. You can imagine that over time this code might continue to grow and grow and become more and more prone for errors.&lt;br /&gt;
&lt;br /&gt;
Before we get too far, let's take a side trip and look at what messages are and what types exist.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Types of Messages&lt;/h2&gt;&lt;br /&gt;
&lt;h3&gt;Observer Events&lt;/h3&gt;&lt;br /&gt;
An observer event is probably one that you are most used to if you are familiar with front-end web development. In relation to the DOM you can think of this as adding event handlers to an element. The element has a direct reference to the callbacks that will be invoked when the event type occurs. &lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5235011.js?file=observer-events.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Mediated Events&lt;/h3&gt;&lt;br /&gt;
A mediated event or message has become more common the last several years in front-end web development. The main idea here is that there is another entity that keeps track of publishing and subscribing of messages. The main difference between this and Observer events is that Mediated events aren't tied directly to the subject that invoked it.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5235011.js?file=mediated-events.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h4&gt;Implementations&lt;/h4&gt;&lt;br /&gt;
There are several libraries out there that facilitate mediated events. The following is a list of various libraries that you may want to choose from. My recommendation is that you look at Jim's &lt;a href="https://github.com/postaljs/postal.js"&gt;postal.js&lt;/a&gt; library.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Ben Alman's (&lt;a href="http://twitter.com/cowboy" target="_blank"&gt;@cowboy&lt;/a&gt;) &lt;a href="https://github.com/cowboy/jquery-tiny-pubsub"&gt;Tiny jQuery Pub/Sub&lt;/a&gt; library&lt;/li&gt;
&lt;li&gt;Peter Higgin's (&lt;a href="http://twitter.com/phiggins" target="_blank"&gt;@phiggins&lt;/a&gt;) &lt;a href="https://github.com/phiggins42/bloody-jquery-plugins/blob/master/pubsub.js"&gt;pubsub.js&lt;/a&gt; library&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jim Cowart's (&lt;a href="http://twitter.com/ifandelse" target="_blank"&gt;@ifandelse&lt;/a&gt;) &lt;a href="https://github.com/postaljs/postal.js"&gt;postal.js&lt;/a&gt; library ← Recommended&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Dustin Diaz's (&lt;a href="http://twitter.com/ded" target="_blank"&gt;@ded&lt;/a&gt;) &lt;a href="https://github.com/ded/reqwest"&gt;reqwest&lt;/a&gt; library&lt;/li&gt;
&lt;li&gt;appendTo's (&lt;a href="http://twitter.com/appendTo" target="_blank"&gt;@appendTo&lt;/a&gt;) &lt;a href="http://amplify.js/"&gt;AmplifyJS Pub/Sub&lt;/a&gt; component&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Hybrid Events&lt;/h3&gt;&lt;br /&gt;
There is another type of event that is sort of a hybrid between observer and mediated. This type looks like a mediated event, but if you look hard enough there you could actually trace the origin of the event back to the original subject. A good example of this is jQuery's delegated event model. Delegated events are great, but it is based on the concept of events bubbling up the DOM and therefore we can trace where it came from. &lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;Example&lt;/h4&gt;&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5235011.js?file=hybrid-events.js"&gt;&lt;/script&gt;&lt;br /&gt;
By the way, I don't recommend using the &lt;code&gt;$._data()&lt;/code&gt; method as it is undocumented and therefore not guaranteed that it will be available in future versions of jQuery. It is an internal helper method that jQuery currently uses under the covers. However, I did want to show you that there is a way to poke around and get at information that the subscriber shouldn't have in a real "mediated event", which is why I'm calling it a hybrid event. Don't get me wrong, I love jQuery's delegated events. I just wanted to show how it is a hybrid of the two above concepts.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Which One Should Be Used?&lt;/h3&gt;&lt;br /&gt;
That information is all fine and good, but what type of event/message should you be using and when? That is a great question and one that my friend Jim addressed in a recent post that he wrote. The following is a quote from his article...&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;"...use observer 'locally', inside a component, mediator 'remotely' between components. No matter what, be ready to use both in tandem.' --&lt;a href="http://freshbrewedcode.com/jimcowart/2013/02/07/client-side-messaging-essentials/" target="_blank"&gt;Jim Cowart&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
Jim recommends using observer events (jQuery's &lt;code&gt;.on()&lt;/code&gt; method) when communicating within a module and to use mediated events (postal.js) when communicating between modules.&lt;br /&gt;
&lt;br /&gt;
Another technique that Jim brings up in his article is to promote observer events into mediated events, which gives you the both of both worlds. He has some nice examples showing how that could look. I encourage you to take a look at his article referenced below in bold.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Additional Resources&lt;/h2&gt;&lt;br /&gt;
If you are interesting in more information about the above concepts you may consider looking through some of the following resources about events and messaging. &lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Jim Cowart's (&lt;a href="http://twitter.com/ifandelse" target="_blank"&gt;@ifandelse&lt;/a&gt;) &lt;a href="http://freshbrewedcode.com/jimcowart/2013/02/07/client-side-messaging-essentials/" target="_blank"&gt;Client-side Messaging Essentials&lt;/a&gt; article&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Addy Osmani's (&lt;a href="http://twitter.com/addyosmani" target="_blank"&gt;@addyosmani&lt;/a&gt;) &lt;a href="http://msdn.microsoft.com/en-us/magazine/hh201955.aspx"&gt;Understanding the Publish/Subscribe Pattern for Greater JavaScript Scalability&lt;/a&gt; article&lt;/li&gt;
&lt;li&gt;Rebecca Murphey's (&lt;a href="http://twitter.com/rmurphey" target="_blank"&gt;@rmurphey&lt;/a&gt;) &lt;a href="http://net.tutsplus.com/tutorials/javascript-ajax/loose-coupling-with-the-pubsub-plugin/"&gt;Loose Coupling with the pubsub Plugin&lt;/a&gt; screencast&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Loosely Coupled Code&lt;/h2&gt;&lt;br /&gt;
I was tempted to write the following code using Backbone.js or create constructor functions, but in order to keep it simple and convey the idea of messaging I tried to remove all of that. So, this probably isn't what you'd have in your code-base, but hopefully it gets the point across. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/5235011.js?file=loosely-coupled.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com/"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Red Bird and you can also use the arrow keys. If it takes you too long to destroy the pigs you might want to consider pressing the &lt;code&gt;space bar&lt;/code&gt; several times ;)&lt;/blockquote&gt;&lt;br /&gt;
&lt;a href="http://jsfiddle.net/Gue8x/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;" target="_blank"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-PRXEAO-ZYuM/UVPOS_7QrnI/AAAAAAAAYoQ/VntWqZzDWeI/s1600/Screenshot+on+3.27.2013+at+11.56.39+PM.png" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Using events and messages across your web application can help with communication. Events allow a component to communicate with itself and messages can enable other components to listen in without having a hard dependency.&lt;br /&gt;
&lt;br /&gt;
There are many other front-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/3219085302078888445/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3219085302078888445?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3219085302078888445?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" title="Angry Birds of JavaScript: Blue Bird - Events" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-6ILPSz-pyp0/UVEnzs_iVfI/AAAAAAAAYVE/yXkm3RWutRs/s72-c/angry-birds-game-for-windows-1.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DUUFRXo4fCp7ImA9WhBXFEk.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-3870617503117023564</id><published>2013-03-25T00:01:00.001-05:00</published><updated>2013-03-28T00:06:54.434-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-03-28T00:06:54.434-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript: Red Bird - IIFE</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-gdPxI78dJRM/UUPoi2KHFkI/AAAAAAAAX94/M6gVKm4DN64/s1600/Loading_screen.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="179" src="http://3.bp.blogspot.com/-gdPxI78dJRM/UUPoi2KHFkI/AAAAAAAAX94/M6gVKm4DN64/s320/Loading_screen.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
In this post we will take a look at the Red Bird who attacks with the force of their trusty IIFE, the basic block of all privacy.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;What Was Stolen by the Pigs?&lt;/h2&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-JMM-_2Tl7Es/UUOFH81EAUI/AAAAAAAAX8k/GxsgENgc4kY/s1600/red-bird.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-JMM-_2Tl7Es/UUOFH81EAUI/AAAAAAAAX8k/GxsgENgc4kY/s200/red-bird.png" width="182" /&gt;&lt;/a&gt;&lt;/div&gt;For ages the birds used to litter the global namespace (the window object) with their custom objects and functions. Over time the birds slowly learned techniques to protect their objects from the global namespace, however, since the recent pig invasion all of their anti-global secrets have been stolen! Thankfully the birds are fortunate that a one foul exists with the knowledge of this secret and plans to attack the pigs to unleash what is rightfully theirs.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;How Objects Become Global?&lt;/h2&gt;&lt;br /&gt;
There are several ways that an object can become global. Part of the battle is just knowing the various ways.&lt;br /&gt;
&lt;br /&gt;
1. &lt;strong&gt;Declaring an Object in the Window Scope&lt;/strong&gt; &lt;!-- TODO: Is this called the Window Scope? Top Level Scope? --&gt;&lt;br /&gt;
&lt;br /&gt;
In the following example there two variables declared, &lt;code&gt;type&lt;/code&gt; and &lt;code&gt;attack&lt;/code&gt;. These variables were declared in the top level scope and therefore are accessible off of the &lt;code&gt;window&lt;/code&gt; object. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=global-variables.js"&gt;&lt;/script&gt;&lt;br /&gt;
2. &lt;strong&gt;Not Declaring an Object in Any Scope&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
One of the most dangerous and easiest things to do in JavaScript is to accidentally declare a global variable when you didn't mean to. If you forget to declare a variable then JavaScript declares it for you as a global! This is usually not what you meant to do and could expose parts of your application that you didn't intend.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=not-declaring-variable.js"&gt;&lt;/script&gt;&lt;br /&gt;
3. &lt;strong&gt;Specifically Adding an Object to the Window&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
You also have the opportunity to expose variables to the global namespace intentionally. You can easily do this by accessing the &lt;code&gt;window&lt;/code&gt; object and adding a property or method manually. It isn't a good idea to use this technique deep inside your code, but it is worth nothing that you can.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=explicit-global.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h2&gt;Why Are Global Objects a Problem?&lt;/h2&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Conflicts within Your Code&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
There is a risk that developers within your own company may define the same function, method, or property that already exists in your application. If you have no mechanism to reduce the number of items in the global namespace your risk of accidentally reassigning a variable grows as your application gets larger and more complex.&lt;br /&gt;
&lt;br /&gt;
You may dismiss this reason because you have rigid code reviews and all your developers know your codebase inside out. If that describes you, then check out the next reason ;)&lt;br /&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conflicts with Your Code and Third-Party Libraries&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Another danger of having multiple global objects is that your code could conflict with third-party libraries that you are using. There are a lot of libraries, plugins, and frameworks out there and not all of them are as aware and conscious about keeping their global variables to a minimum. Your code and the libraries you include could clash and override each-other's behavior which can cause unexpected results.&lt;br /&gt;
&lt;br /&gt;
You may dismiss this reason because you deeply scrutinize all third-party libraries that your team uses and are fully aware of what global variables are exposed by these libraries. If that describes you, then check out the next reason :)&lt;br /&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Conflicts with Your Code and Browser Add-ons/Extensions/Plugins&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The final danger of having multiple global objects is that your code could conflict with the browser itself. What!?! Lets take Google Chrome for an example. Chrome's add-ons are JavaScript based and all of your installed add-ons run on your web page when it is loaded. You never know what add-ons your users have installed and as a result there is a risk that those add-ons will expose global variables that conflict with your code-base.&lt;br /&gt;
&lt;br /&gt;
Does this seem far-fetched? Well, it can at first, but I've actually seen a high profile website (not going to mention which one) run into this very problem. I was trying to use the website and it was broken. I knew the developer so I reached out to him. After some back and forth it turned out I had an add-on installed that broke the website. I contacted the add-on author and they updated their code and now all is fine.&lt;br /&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;h2&gt;Various Ways to Protect Yourself&lt;/h2&gt;&lt;br /&gt;
Although the above code snippets were very small and simple, they all exposed way too many variables to the global namespace. So, how do we protect ourselves?&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Object Literal&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The easiest way to help prevent global variable proliferation is to protect yourself with an object literal that limits gathers all objects that would have been global and attaches them to once central object.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=object-literal.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Immediately Invoked Function Expression&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
The Immediately Invoked Function Expression (IIFE) is another technique to get around the global issue. This technique is more complicated than the Object Literal, but provides much more power as well. This technique allows the developer to expose public and private properties and methods to the consumer.&lt;br /&gt;
&lt;br /&gt;
Before we get into what this looks like, lets work through some of their weird syntax that we are about to see. The scoping of variables in JavaScript is determined via the function scope and not block scope. So, if you have a variable declared inside an &lt;code&gt;if&lt;/code&gt; statement for example it would be available everywhere inside its containing function. This might seem a little jarring to some developers that are used to C, C++, C#, Java, or similar languages. &lt;br /&gt;
&lt;br /&gt;
So, we are going to use this functional scope idea to create an anonymous function (function with no name) and immediately invoke it.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=unwrapped-iife.js"&gt;&lt;/script&gt;&lt;br /&gt;
Unfortunately, the above snippet doesn't work in JavaScript because it can't parse it correctly. The idea is solid, but the implementation is off just a little bit. Thankfully, there is an easy way to let JavaScript know that we know what we are doing and that is to surround the expression with an extra set of parenthesis.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=empty-iife.js"&gt;&lt;/script&gt;&lt;br /&gt;
The following pattern is known as the Revealing Module Pattern. You should notice the use of the IIFE to create the special functional scope and the note-worthy part is the end where you &lt;code&gt;return&lt;/code&gt; the parts of the scope that you want to be public to object and anything not returned will be private.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=revealing-module.js"&gt;&lt;/script&gt;&lt;br /&gt;
You may also run across this alternate syntax that is popular in many libraries and frameworks. The pattern uses the IIFE, but this one passes in the global variable to use as a namespace. The &lt;code&gt;window.bird = window.bird || {}&lt;/code&gt; code snippet is a fancy way to check if the &lt;code&gt;bird&lt;/code&gt; object already exists and if it doesn't then to create a new one. Whatever gets added to the object from within the IIFE becomes public and whatever memory isn't attached to the object stays private. The nice thing about this pattern is that it can be repeated and build up a library with various components.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4991287.js?file=parameter-iife.js"&gt;&lt;/script&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Attack!&lt;/h2&gt;&lt;br /&gt;
The following is a simple Angry Birds clone using &lt;a href="http://incompl.github.com/boxbox/"&gt;boxbox&lt;/a&gt;, a framework for the &lt;a href="https://code.google.com/p/box2dweb/"&gt;box2dweb&lt;/a&gt; JavaScript physics library, written by &lt;a href="http://bocoup.com"&gt;Bocoup&lt;/a&gt;'s &lt;a href="http://twitter.com/_gsmith"&gt;Greg Smith&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Press the &lt;code&gt;space bar&lt;/code&gt; to launch the Red Bird and you can also use the arrow keys.&lt;/blockquote&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://jsfiddle.net/hzz3U/1/show" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="392" src="http://1.bp.blogspot.com/-uVcHLO0YlUo/UUPqxGUmyrI/AAAAAAAAX-I/Xjqh5Qn_rEw/s640/angry-birds-jsfiddle-shadow.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;!--&lt;iframe allowfullscreen="allowfullscreen" frameborder="0" src="http://jsfiddle.net/hzz3U/embedded/result,js,resources,html" style="height: 425px; width: 100%;"&gt;&lt;/iframe&gt;--&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
These techniques are vital for a front-end application so that it can protect itself from other code and it also gives the opportunity to structure your code in a way that is encapsulated from its surroundings. &lt;br /&gt;
&lt;br /&gt;
There are many other frotn-end architecture techniques that have been stolen by the pigs. Tune in next time as the next Angry Bird takes its revenge! Dun, dun, daaaaaaa!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/3870617503117023564/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3870617503117023564?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3870617503117023564?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" title="Angry Birds of JavaScript: Red Bird - IIFE" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-gdPxI78dJRM/UUPoi2KHFkI/AAAAAAAAX94/M6gVKm4DN64/s72-c/Loading_screen.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEEHSHw8eip7ImA9WhBWF0s.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-4077775328035479832</id><published>2013-03-25T00:01:00.000-05:00</published><updated>2013-04-12T06:37:19.272-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-12T06:37:19.272-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Angry Birds of JavaScript" /><title>Angry Birds of JavaScript Series</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-x2EkpXGeIiU/UUOB_nmgpdI/AAAAAAAAX8Y/RlZdGySZWwE/s1600/5641819490_2cb448303e.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="332" src="http://3.bp.blogspot.com/-x2EkpXGeIiU/UUOB_nmgpdI/AAAAAAAAX8Y/RlZdGySZWwE/s640/5641819490_2cb448303e.jpg" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Introduction&lt;/h3&gt;&lt;br /&gt;
A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! A team of special agent hero birds will attack those despicable pigs until they recover what is rightfully theirs, front-end JavaScript architecture!&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Meet the Special Agent Hero Birds&lt;/h3&gt;&lt;br /&gt;
Over the course of the next several weeks you'll be introduced to the following team of super hero birds...&lt;br /&gt;
&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-JMM-_2Tl7Es/UUOFH81EAUI/AAAAAAAAX8g/dnqsFpJFfGo/s200/red-bird.png" width="182" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Red Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Red bird attacks with the force of their trusty IIFE, the basic block of all privacy.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-red-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-LxI_h-dYcRQ/UUOFZbQ4heI/AAAAAAAAX8w/aVsf9BQfQRU/s200/blue-bird-1.png" width="173" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Blue Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Blue Bird triggers events and messages that scatter to infiltrate the pig's castle.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-blue-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-32n5qOeDtdk/UUOFi38IgEI/AAAAAAAAX84/CIoyxmLMmkY/s1600/yellow-bird.png" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Yellow Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Yellow Bird comes with a RequireJS speed booster and dynamically injects scripts against those pesky swine.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-yellow-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-4WycZj513eE/UUOFnIF28JI/AAAAAAAAX9A/Y87gPOBtyxk/s1600/black-bird.png" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Black Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Black Bird proves to be a much more organized approach to fighting these porkers and introduces the Backbone.js bomb to their dismay.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-black-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-yywG6-06kUM/UUOFrOcP0iI/AAAAAAAAX9I/iotHWUvRecY/s1600/white-bird.png" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;White Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The White Bird appears to be seemingly harmless, but when it pulls out it's strict coding style and bursts of quality checks the hogs are sure to squeal.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-white-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-rRVmKl9KUv4/UUOFu9VUPNI/AAAAAAAAX9Q/rMstM-JU-e8/s1600/green-bird.png" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Green Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Green Bird can reach all of those hard to reach places and will mock and spy those stealing swine right where it hurts!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-green-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-YT-EBrpkliY/UUOFy_dcttI/AAAAAAAAX9Y/Q4VET7T9UaY/s200/orange-bird.png" width="181" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Orange Bird&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Orange Bird starts out small with a simple template, but then expands itself into a DOM blast that will surely send the message that the birds mean business.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-orange-bird.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-J61UAuZaSPU/UUOF3XpAjvI/AAAAAAAAX9g/yliiflRrXXU/s1600/big-brother-bird.png" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Big Brother&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Big Brother pulls out the big guns with his finite state machine and other proven design patterns of destruction.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-big-brother.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;div style="width: 325px; float: left;"&gt;&lt;img border="0" height="160" src="http://4.bp.blogspot.com/-MQvW-RP8-f0/UUOF7QwJY9I/AAAAAAAAX9o/7_-CH_56XPY/s320/mighty-eagle.png" width="320" /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style="float: left; width: 300px; margin-top: 45px;"&gt;&lt;h4&gt;Mighty Eagle&lt;/h4&gt;&lt;br /&gt;
&lt;span&gt;The Mightly Eagle uses the most superior weapon of them all, a suite of tools that can organize and deploy all the other birds into battle against their soon to be vanquished foe.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;Status: &lt;strong&gt;&lt;a href="http://www.elijahmanor.com/2013/04/angry-birds-of-javascript-mighty-eagle.html" target="_blank"&gt;Published&lt;/a&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style="clear: both; width: 100%;"&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: smaller;"&gt;Images provided via &lt;a href="http://angrybirds.wikia.com/wiki/Mighty_Eagle"&gt;Angry Birds Wiki&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
The above series will be presented at the upcoming &lt;a href="http://www.elijahmanor.com/2013/03/front-end-web-conference.html"&gt;&amp;lt;anglebrackets /&amp;gt;&lt;/a&gt; and &lt;a href="http://www.elijahmanor.com/2013/02/fluentconf-advanced-jquery-training.html"&gt;FluentConf&lt;/a&gt; conferences and possibly others. I hope you enjoy the series. I am having fun putting it together and I look forward to giving it in front of an audience ;)</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/4077775328035479832/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4077775328035479832?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4077775328035479832?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/03/angry-birds-of-javascript-series.html" title="Angry Birds of JavaScript Series" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-x2EkpXGeIiU/UUOB_nmgpdI/AAAAAAAAX8Y/RlZdGySZWwE/s72-c/5641819490_2cb448303e.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CUQBSXw9eip7ImA9WhBQF0Q.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-5623694557464841019</id><published>2013-03-20T10:29:00.000-05:00</published><updated>2013-03-20T10:29:18.262-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-03-20T10:29:18.262-05:00</app:edited><title>New Beginnings</title><content type="html">&lt;h3&gt;Introduction&lt;/h3&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-3gpeaMkxAWI/UUnUH9cAd0I/AAAAAAAAX-Y/gLYjtg_MZPw/s1600/appendto-logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="69" src="http://4.bp.blogspot.com/-3gpeaMkxAWI/UUnUH9cAd0I/AAAAAAAAX-Y/gLYjtg_MZPw/s320/appendto-logo.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;Today is my last day at &lt;a href="http://appendto.com/"&gt;appendTo, LLC&lt;/a&gt;. I've been working with appendTo for over 2.5 years and have been doing a combination of architecture reviews, project work, staff augmentation, and preforming on-site and virtual remote trainings. &lt;br /&gt;
&lt;br /&gt;
I've learned a lot while at appendTo. I've grown in my confidence as a developer and a trainer and I've valued working alongside talented developers and friends. I appreciate the time I've been at appendTo, but it is time to move on.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Going Out On My Own&lt;/h3&gt;&lt;br /&gt;
I've decided to go out on my own and start my own business! This day comes with a mixed bag full of emotions. My company name is &lt;strong&gt;Manorism, Inc.&lt;/strong&gt; I've purchased the manorism.net domain (haven't launched it yet) and hope to acquire the .com from its current owner. &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-NY93xjozUhc/UUnUOv8jXKI/AAAAAAAAX-g/5FrzLLbCDjY/s1600/pluralsight.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="92" src="http://1.bp.blogspot.com/-NY93xjozUhc/UUnUOv8jXKI/AAAAAAAAX-g/5FrzLLbCDjY/s320/pluralsight.png" width="320" /&gt;&lt;/a&gt;My company will primarily center around training. My initial focus will involve creating several &lt;a href="http://pluralsight.com/"&gt;PluralSight&lt;/a&gt; videos and then I hope to branch out to do remote/on-site trainings, workshops at conferences, and some consulting on the side. I start on my 1st PluralSight course starting tomorrow and it should be available in about a month.&lt;br /&gt;
&lt;br /&gt;
I'm not going anywhere and if anything else you should see more of me than you have previously ;) Again, thanks appendTo and keep your eyes open for Manorism, Inc.</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/5623694557464841019/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/03/new-beginnings.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5623694557464841019?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5623694557464841019?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/03/new-beginnings.html" title="New Beginnings" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-3gpeaMkxAWI/UUnUH9cAd0I/AAAAAAAAX-Y/gLYjtg_MZPw/s72-c/appendto-logo.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DUUCQ3gzeyp7ImA9WhBQEE0.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-1824860977948805210</id><published>2013-03-11T08:06:00.000-05:00</published><updated>2013-03-11T08:07:42.683-05:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-03-11T08:07:42.683-05:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Conference" /><title>&lt;anglebrackets /&gt; Front-End Web Conference</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://anglebrackets.org/default.aspx" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="87" src="http://3.bp.blogspot.com/-tpL56DCy-rg/UT1CWJOOPJI/AAAAAAAAXz4/l8Yu1q90PhY/s640/AngleBracketsLogo-Bits-etm.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://anglebrackets.org/default.aspx" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-H8wldfy7CJo/UT1CbSIUZSI/AAAAAAAAX0A/RzUfKTyQ8Oc/s1600/bg-etm.png" /&gt;&lt;/a&gt;A new front-end developer conference is starting in Las Vegas April 8-11! This conference will be focusing primarily on the front-end concerns such as HTML5, CSS3, and JavaScript. &lt;br /&gt;
&lt;br /&gt;
This event reminds me a lot of the Microsoft MIX conferences that used to be held for the last several years. I am glad to see something like this conference come to fruition and I'm honored to be one of the speakers chosen for its 1st meeting.&lt;br /&gt;
&lt;br /&gt;
In addition, this conference will be taking place in-tandem with another conference called &lt;a href="http://devintersection.com/"&gt;Dev Intersection &amp;amp; SQL Intersection&lt;/a&gt;. This other conference will be more focused on Microsoft and .NET technologies. These two conferences will be held at the time and location so you can hop between the conferences as you wish.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;If you are interested in attending either of the conferences you can use the "MANOR" discount code for $50 off your &lt;a href="http://anglebrackets.org/default.aspx"&gt;&amp;lt;anglebrackets /&amp;gt; Registration&lt;/a&gt; OR &lt;a href="http://devintersection.com/"&gt;Dev Intersection &amp;amp; SQL Intersection Registration&lt;/a&gt; price.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Speakers&lt;/h3&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-TT_FLzgWLwc/UT1G8r_dEWI/AAAAAAAAX0Y/ErhcO3ty69U/s1600/Screen+Shot+2013-03-10+at+10.52.03+PM.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-TT_FLzgWLwc/UT1G8r_dEWI/AAAAAAAAX0Y/ErhcO3ty69U/s1600/Screen+Shot+2013-03-10+at+10.52.03+PM.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
At the &amp;lt;anglebrackets /&amp;gt; conference I'll be speaking alongside many well known speaker such as&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Scott Allen&lt;/li&gt;
&lt;li&gt;Todd Anglin&lt;/li&gt;
&lt;li&gt;Justin Beckwith&lt;/li&gt;
&lt;li&gt;Miguel Castro&lt;/li&gt;
&lt;li&gt;Jim Cowart&lt;/li&gt;
&lt;li&gt;Damian Edwards&lt;/li&gt;
&lt;li&gt;Jason Follas&lt;/li&gt;
&lt;li&gt;Brady Gaster&lt;/li&gt;
&lt;li&gt;Phil Haack&lt;/li&gt;
&lt;li&gt;Scott Hanselman&lt;/li&gt;
&lt;li&gt;Christian Hellmann&lt;/li&gt;
&lt;li&gt;Burke Holland&lt;/li&gt;
&lt;li&gt;Billy Hollis&lt;/li&gt;
&lt;li&gt;Scott Hunter&lt;/li&gt;
&lt;li&gt;Denise Jacobs&lt;/li&gt;
&lt;li&gt;Brian Noyes&amp;nbsp;&lt;/li&gt;
&lt;li&gt;John Papa&lt;/li&gt;
&lt;li&gt;Jonathan Snook&lt;/li&gt;
&lt;li&gt;Lea Verou&lt;/li&gt;
&lt;li&gt;Dan Wahlin&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Sessions&lt;/h3&gt;&lt;br /&gt;
Some of the sessions that look interesting to me are...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;5 Tips for Better JavaScript&lt;/li&gt;
&lt;li&gt;ASP.NET - Don't Do THAT! Common Mistakes and Pitfalls&lt;/li&gt;
&lt;li&gt;Break Out Of The Browser With HTML5&lt;/li&gt;
&lt;li&gt;Comparing JavaScript Frameworks: Ember, Angular, and Knockout&lt;/li&gt;
&lt;li&gt;Eventing and Messaging in JavaScript&lt;/li&gt;
&lt;li&gt;Getting Started With Require.js&lt;/li&gt;
&lt;li&gt;HTML5 for Business: Forms and Input Validation&lt;/li&gt;
&lt;li&gt;Modern Single Page Applications with &amp;nbsp;HTML5, CSS3, JS, ASP.NET and Visual Studio&lt;/li&gt;
&lt;li&gt;etc...&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
I will be presenting the following two sessions at the event&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://www.anglebrackets.org/sessions.aspx#ContentPlaceHolderMain_SessionList_Label1_2"&gt;Angry Birds of Modern JavaScript Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.anglebrackets.org/sessions.aspx#ContentPlaceHolderMain_SessionList_Label1_19"&gt;Learning Backbone.js by Refactoring Spaghetti jQuery Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;See You There!&lt;/h3&gt;&lt;br /&gt;
It should be a fun event and I hope to see you there. There are also some nice workshops you might want to check out. If you are able to make it then come up after one of my talks or stop me somewhere, I'd enjoy getting to meet you. &lt;br /&gt;
&lt;br /&gt;
Remember the "MANOR" discount code for $50 off your &lt;a href="http://anglebrackets.org/default.aspx"&gt;&amp;lt;anglebrackets /&amp;gt; Registration&lt;/a&gt; OR &lt;a href="http://devintersection.com/"&gt;Dev Intersection &amp;amp; SQL Intersection Registration&lt;/a&gt; price.</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/1824860977948805210/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/03/front-end-web-conference.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1824860977948805210?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1824860977948805210?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/03/front-end-web-conference.html" title="&amp;lt;anglebrackets /&amp;gt; Front-End Web Conference" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-tpL56DCy-rg/UT1CWJOOPJI/AAAAAAAAXz4/l8Yu1q90PhY/s72-c/AngleBracketsLogo-Bits-etm.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;CEYDRXw5eCp7ImA9WhBTFko.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-3513253845747338635</id><published>2013-02-12T00:01:00.000-06:00</published><updated>2013-02-12T06:29:34.220-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-12T06:29:34.220-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>jQuery Object Quacks like an Array Duck</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-sYshvcU0kH8/URnJNP0cEfI/AAAAAAAAXWk/Q6Va0wZnPOc/s1600/Screen+Shot+2013-02-11+at+8.44.07+PM.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-sYshvcU0kH8/URnJNP0cEfI/AAAAAAAAXWk/Q6Va0wZnPOc/s200/Screen+Shot+2013-02-11+at+8.44.07+PM.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;jQuery Array-like Object&lt;/h3&gt;&lt;br /&gt;
I'm sure you've heard of the old saying, "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck".&lt;br /&gt;
&lt;br /&gt;
Well, a simular statement could be said about the &lt;code&gt;jQuery Object&lt;/code&gt;. If the &lt;code&gt;jQuery Object&lt;/code&gt; looks like an array, indexes like an array, console.logs like an array, then it probably is an array... err, well, but in this case it's NOT an array!&lt;br /&gt;
&lt;br /&gt;
Let's unpack this a little more and see what sense we can make out of it. The following snippet of code invokes the &lt;code&gt;jQuery Function&lt;/code&gt; and performs a selection from the DOM and then accesses the returned &lt;code&gt;jQuery Object&lt;/code&gt; to locate the DOM element at index 2, which feels an awful lot like an array.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4759928.js?file=jquery-array-like-object.js"&gt;&lt;/script&gt;&lt;br /&gt;
Upon further examination in the console the &lt;code&gt;jQuery Object&lt;/code&gt; is indeed an &lt;code&gt;object&lt;/code&gt; (not an array) as indicated by the &lt;code&gt;$.type()&lt;/code&gt; utility method.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-rPee0xBDS-s/URnKs5b1_3I/AAAAAAAAXXI/xoRpgfGk1Ew/s1600/jquery-array-like-object.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-rPee0xBDS-s/URnKs5b1_3I/AAAAAAAAXXI/xoRpgfGk1Ew/s1600/jquery-array-like-object.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;Note: You might notice that I am using the lesser known &lt;code&gt;$.type()&lt;/code&gt; utility method to determine the type of the variable. I am not using the &lt;code&gt;typeof&lt;/code&gt; operator because it evaluates to "object" for both arrays and objects. The &lt;code&gt;$.type()&lt;/code&gt; method returns much more useful data &lt;a href="http://api.jquery.com/jquery.type/"&gt;http://api.jquery.com/jquery.type/&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
Something of interest in the above screenshot is the grayed out &lt;code&gt;__proto__&lt;/code&gt; property. That is where all the jQuery goodness (functionality) can be found such as &lt;code&gt;.fadeOut()&lt;/code&gt;, &lt;code&gt;.on()&lt;/code&gt;, &lt;code&gt;.addClass()&lt;/code&gt;, and all the other methods jQuery provides.&lt;br /&gt;
&lt;br /&gt;
After some digging in the jQuery source code I came across the following &lt;code&gt;merge&lt;/code&gt; method where the array results of the DOM selection gets copied over to the &lt;code&gt;jQuery Object&lt;/code&gt;. In addition to mapping over these values jQuery also provides a &lt;code&gt;.length&lt;/code&gt; property and a &lt;code&gt;.splice()&lt;/code&gt; method which enables itself to mimic an array.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4759928.js?file=jquery-internal-object-array-merge.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Making a Custom Array-like Object&lt;/h3&gt;&lt;br /&gt;
So, what about making our own custom array-like object!?! The following small snippet of JavaScript defines an object and then assigns a set of key/value pairs. In order to mimic an array we need to add a &lt;code&gt;.length&lt;/code&gt; property and expose a &lt;code&gt;.splice()&lt;/code&gt; method borrowed from the array. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4759928.js?file=custom-array-like-object.js"&gt;&lt;/script&gt;&lt;br /&gt;
The following is a screenshot of what is console.logged after executing the above code snippet. You will see that our &lt;code&gt;array_like&lt;/code&gt; object is treated as if it were an array just the like &lt;code&gt;jQuery Object&lt;/code&gt;... yay!&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-mXHqq1rDo30/URnKyAezvrI/AAAAAAAAXXQ/Rm9eNRrGVMM/s1600/custom-array-like-object.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-mXHqq1rDo30/URnKyAezvrI/AAAAAAAAXXQ/Rm9eNRrGVMM/s1600/custom-array-like-object.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;Note: If we take off the &lt;code&gt;.length&lt;/code&gt; property or the &lt;code&gt;.splice()&lt;/code&gt; method then the custom object will no longer appear as an array in the console. They are both necessary.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
So, inductive reasoning might be a good thing most of the time, but in this case the &lt;a href="http://en.wikipedia.org/wiki/Duck_test"&gt;Duck Test&lt;/a&gt; failed us. You can play around with the code snippets above by looking at the following &lt;a href="http://jsfiddle.net/elijahmanor/BZSne/"&gt;JSFiddle&lt;/a&gt;.</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/3513253845747338635/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/02/jquery-object-quacks-like-array-duck.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3513253845747338635?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/3513253845747338635?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/02/jquery-object-quacks-like-array-duck.html" title="jQuery Object Quacks like an Array Duck" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-sYshvcU0kH8/URnJNP0cEfI/AAAAAAAAXWk/Q6Va0wZnPOc/s72-c/Screen+Shot+2013-02-11+at+8.44.07+PM.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0YMQHg4eip7ImA9WhBTEU4.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-9611876979886149</id><published>2013-02-05T00:05:00.000-06:00</published><updated>2013-02-06T00:13:01.632-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-06T00:13:01.632-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CSS3" /><category scheme="http://www.blogger.com/atom/ns#" term="Tip" /><category scheme="http://www.blogger.com/atom/ns#" term="Twitter Bootstrap" /><category scheme="http://www.blogger.com/atom/ns#" term="CSS" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Animating a Twitter BootStrap Icon with CSS3</title><content type="html">&lt;h2&gt;Introduction&lt;/h2&gt;&lt;br /&gt;
So, I was already using &lt;a href="http://twitter.github.com/bootstrap/"&gt;Twitter Bootstrap&lt;/a&gt; on a project recently and I had a refresh icon that I wanted to use a button. The markup for my icon looked very much like the following snippet...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4617496.js?file=fiddle.html"&gt;&lt;/script&gt;&lt;br /&gt;
The previous markup renders as the following...&lt;br /&gt;
&lt;br /&gt;
&lt;iframe style="width: 100%; height: 75px" src="http://jsfiddle.net/uDCDh/embedded/result,html" allowfullscreen="allowfullscreen" frameborder="0"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
That is all fine and dandy, however, I thought it would be neat if the refresh icon would rotate when the clicked until that action was complete. &lt;br /&gt;
&lt;br /&gt;
To implement this feature I decided to use a CSS3 animation.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Note: At the time of writing this CSS3 animation is currently supported in IE10, Firefox 16+, Chrome 23+, Safari 5.1+, Opera 12.1+, iOS 3.2+, Android 2.1+, &amp; Blackberry 7.0+ &lt;a href="http://caniuse.com/#feat=css-animation"&gt;&lt;small&gt;Reference: Can I Use?&lt;/small&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
&lt;h2&gt;CSS3 Animation&lt;/h2&gt;&lt;br /&gt;
If you don't already know about CSS3 Animation you can pick up a primer at the following locations...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/CSS/Tutorials/Using_CSS_animations"&gt;MDN: Using CSS Animations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://coding.smashingmagazine.com/2011/09/14/the-guide-to-css-animation-principles-and-examples/"&gt;The Guide to CSS Animation Principles and Examples&lt;/a&gt; by &lt;a href="https://twitter.com/2dforever"&gt;Tom WaterHouse&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
I ended up using the following CSS to get the animation to work...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4617496.js?file=fiddle-standard.css"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;blockquote&gt;Note: You may have noticed that I'm not using vendor prefixes in the above CSS. For this demo I am using only the standard prefix-free styles and using &lt;a href="https://twitter.com/leaverou"&gt;Lea Verou&lt;/a&gt;'s &lt;a href="http://leaverou.github.com/prefixfree/"&gt;-prefix-free&lt;/a&gt; library to dynamically add the vendor prefixed styles at runtime. Now, you may or may not want to use this library for production, but it sure makes it nice for blog posts and jsFiddles!&lt;/blockquote&gt;&lt;br /&gt;
The above CSS defines a class named &lt;code&gt;icon-refresh-animate&lt;/code&gt; that assigns the animation, how long it should take, how many times it should iterate, and what type of algorithm to use. The class references the &lt;code&gt;rotateThis&lt;/code&gt; keyframes which defines what the beginning and end state of the animation should look like. In this case the animation will rotate the element from 0 degrees to 360 degrees.&lt;br /&gt;
&lt;br /&gt;
Once I got the CSS3 situated, I moved on to writing some JavaScript to wire up the animation. The following code snippet adds the &lt;code&gt;icon-refresh-animation&lt;/code&gt; class to the icon when the anchor is clicked. Once the class has been added the animation begins. Then the code kicks off a &lt;code&gt;window.setTimeout&lt;/code&gt; to simulate some kind of asynchronous action and when complete the class is removed, therefore stoping the animation.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4617496.js?file=fiddle.js"&gt;&lt;/script&gt;&lt;br /&gt;
You can interact with the final solution in the following jsFiddle. You'll need to &lt;strong&gt;click the icon&lt;/strong&gt; in order to kick off the 2 second animation.&lt;br /&gt;
&lt;br /&gt;
&lt;iframe style="width: 100%; height: 75px" src="http://jsfiddle.net/kVHbV/embedded/result,html,css,resources" allowfullscreen="allowfullscreen" frameborder="0"&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;br /&gt;
&lt;img src="https://a248.e.akamai.net/camo.github.com/4e5b8ec5315f5c72410b96c1331a8b37b338b4c0/687474703a2f2f662e636c2e6c792f6974656d732f3247306e304d316131463239314332573230337a2f626162792d6b6f6d6261742e676966" style="padding: 5px 0px 5px 15px; float: right;" /&gt;So, instead of looking for a GIF to animate your icon, why don't you try taking your ordinary element and make them come alive with a little CSS3 spice. Who needs animated GIFs anyway? &lt;br /&gt;
&lt;br /&gt;
Now, get going and get your baby ninja talents to work. Okay, I admit animated GIFs are cool, but not for rotating your icons ;)&lt;br /&gt;
&lt;br /&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/9611876979886149/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/02/animating-twitter-bootstrap-icon-with.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/9611876979886149?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/9611876979886149?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/02/animating-twitter-bootstrap-icon-with.html" title="Animating a Twitter BootStrap Icon with CSS3" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DU4EQXg7cSp7ImA9WhNaGUg.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-7886136885416906358</id><published>2013-02-04T00:05:00.000-06:00</published><updated>2013-02-04T00:05:00.609-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-04T00:05:00.609-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="Conference" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>FluentConf Advanced jQuery Training &amp; Session</title><content type="html">&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-FsOHlbHNDTg/UQTH_iM4PfI/AAAAAAAAW-Q/HntS_wwqaVs/s1600/Fluent3.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-FsOHlbHNDTg/UQTH_iM4PfI/AAAAAAAAW-Q/HntS_wwqaVs/s1600/Fluent3.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h2&gt;
FluentConf 2013&lt;/h2&gt;
&lt;br /&gt;
Last year I was unable to attend FluentConf, but I'm honored to be on the Program Committee this year. In addition I'll be leading a 3 hour Advanced jQuery workshop and presenting a session on JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;
Training Workshop&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-pO4u2wwedpU/UQdifChEhJI/AAAAAAAAXCY/k1eGH0FTpY8/s1600/jquery-logo-150x150.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-pO4u2wwedpU/UQdifChEhJI/AAAAAAAAXCY/k1eGH0FTpY8/s200/jquery-logo-150x150.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;a href="http://fluentconf.com/fluent2013/public/schedule/detail/28509"&gt;Advanced jQuery Techniques&lt;/a&gt;&lt;/h3&gt;
&lt;br /&gt;
On Tuesday, 05/28/2013 at 9:00am I will lead a workshop on &lt;a href="http://fluentconf.com/fluent2013/public/schedule/detail/28509"&gt;Advanced jQuery Techniques&lt;/a&gt;. This workshop will be last 3 hours long and will contain a combination of both lecture and lab.&lt;br /&gt;
&lt;br /&gt;
If you would like to attend this workshop you can &lt;a href="http://fluentconf.com/fluent2013/public/schedule/add/28509"&gt;add it to your schedule&lt;/a&gt;. You can view all of the other workshops from the &lt;a href="http://fluentconf.com/fluent2013/public/schedule/stype/workshop"&gt;FluentConf website&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
Join appendTo’s Elijah Manor for a dive into advanced topics surrounding the front-end with jQuery. Utilize the jQuery library in the context of large-scale applications by learning how to dramatically improve performance, increase maintainability and reusability, and write cleaner and more concise code. Learn how to adopt a style that is maintainable and scalable while keeping simplicity as a core tenant for successful web development.&lt;/blockquote&gt;
&lt;br /&gt;
&lt;h2&gt;
JavaScript Session&lt;/h2&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-pzZQqoVbl48/UQdiTqb-9wI/AAAAAAAAXCQ/KiXM4Qpvhho/s1600/angry-birds.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-pzZQqoVbl48/UQdiTqb-9wI/AAAAAAAAXCQ/KiXM4Qpvhho/s200/angry-birds.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;a href="http://fluentconf.com/fluent2013/public/schedule/detail/27839"&gt;Angry Birds of Modern JavaScript Development&lt;/a&gt;&lt;/h3&gt;
&lt;br /&gt;
On Wednesday, 05/29/2013 at 1:45pm I will present a session titled &lt;a href="http://fluentconf.com/fluent2013/public/schedule/detail/27839"&gt;Angry Birds of Modern JavaScript Development&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
This is not your ordinary session, I've tried to mix things up by having each Angry Bird represent an area of JavaScript along with its strengths. Some topics covered include code organization, events and messaging, MV* frameworks, prototyping and mocking, design patterns, linting, and build systems. The goal is to defeat the pigs and by doing so produce highly tested quality JavaScript code.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;
A diabolical herd of pigs stole all of the front-end architecture from an innocent flock of birds and now they want it back! A team of special agent hero birds will attack these despicable pigs until they recover what is rightfully theirs, front-end architecture!&lt;br /&gt;
&lt;br /&gt;
The Red Birds attacks with the force of their trusty IIFE, the basic building block of all privacy. The Blue Bird follows in his footsteps and triggers events and messages that scatter to infiltrate the pig’s castle. The Yellow Bird comes with a Require.JS speed booster and dynamically injects scripts against those pesky swine. The Black Bird is soon to follow and he provides a much more organized approach to fighting these porkers and introduces the Backbone.js bomb to their dismay. The White Bird appears to be seemingly harmless, but when it pulls out it’s strict coding style and bursts of quality checks the hogs are sure to squeal. The Green Bird can reach all of those hard to reach places and will mock and spy those stealing swine right where it hurts! The Orange Bird starts out small with a simple template, but then expands itself into a DOM blast that will surely send the message that the birds mean business. The Big Brother is not too far behind and he is pulling out the big guns with his finite state machine and other proven design patterns of destruction. The Mighty Eagle pulls up the ranks with a superior weapon of them all, a suite of tools that can organize and deploy all the other birds into battle against their soon to be be vanquished foe.&lt;/blockquote&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;h2&gt;
appendTo Virtual Live Trainings&lt;/h2&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-GUge2ksHu5I/UQdjZlALRhI/AAAAAAAAXCo/PWu8Nni_fNo/s1600/appendto-logo.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="69" src="http://4.bp.blogspot.com/-GUge2ksHu5I/UQdjZlALRhI/AAAAAAAAXCo/PWu8Nni_fNo/s320/appendto-logo.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
In addition to the previous FluentConf workshop and session I also lead &lt;a href="http://appendto.com/training/"&gt;Virtual Live Trainings&lt;/a&gt; for &lt;a href="http://appendto.com/"&gt;appendTo&lt;/a&gt;. &lt;br /&gt;
&lt;br /&gt;
If your company is interested in a private remote training experience on JavaScript, jQuery, Backbone.js, Underscore.js, RequireJS, or other web technologies please e-mail &lt;a href="mailto:training@appendto.com"&gt;training@appendto.com&lt;/a&gt; for more information.&lt;br /&gt;
&lt;br /&gt;
Here are some of the benefits of a Virtual Live Training (VLT)&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Virtual Live Trainings can be located worldwide. I've performed numerous trainings both in the United States and overseas.&lt;/li&gt;
&lt;li&gt;Virtual Live Trainings are cheaper than our On-Site Trainings because there is no additional cost for travel or hotel fees.&lt;/li&gt;
&lt;li&gt;Virtual Live Trainings are well suited for 1/2 day trainings over a week duration enabling the students to gradually absorb the knowledge and also remain productive at their day job.&lt;/li&gt;
&lt;li&gt;Virtual Live Trainings can be scheduled quicker than an On-Site Training since there is no travel involved.&lt;/li&gt;
&lt;li&gt;Virtual Live Trainings get the same content and labs as an On-Site Training and to make it feel more personable I stream video of myself as well as my screen.&lt;/li&gt;
&lt;/ul&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/7886136885416906358/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/02/fluentconf-advanced-jquery-training.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/7886136885416906358?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/7886136885416906358?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/02/fluentconf-advanced-jquery-training.html" title="FluentConf Advanced jQuery Training &amp; Session" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-FsOHlbHNDTg/UQTH_iM4PfI/AAAAAAAAW-Q/HntS_wwqaVs/s72-c/Fluent3.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;A0IMSH8_eCp7ImA9WhNaFkk.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-5992146909135005839</id><published>2013-01-31T09:59:00.001-06:00</published><updated>2013-01-31T10:26:29.140-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-31T10:26:29.140-06:00</app:edited><title>modern.IE - Analysis and Testing Tools for Web Developers</title><content type="html">&lt;h2&gt;modern.IE&lt;/h2&gt;&lt;br /&gt;
Microsoft has just launched a new website called &lt;a href="http://www.modern.ie/"&gt;modern.IE&lt;/a&gt; that provides a suite of tools to help developers test their websites. &lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-pf-2JD11LJo/UQqSiWkUA1I/AAAAAAAAXHQ/RyifmzbyOQ0/s1600/modernie-crop-m.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="358" src="http://4.bp.blogspot.com/-pf-2JD11LJo/UQqSiWkUA1I/AAAAAAAAXHQ/RyifmzbyOQ0/s640/modernie-crop-m.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Page Analysis Tool&lt;/h3&gt;&lt;br /&gt;
The website integrates a scanning feature that let's you enter your website's URL and it will analyze its contents against a variety of best practices (not only pertaining to IE, but also general concerns).&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-Cs4Vob3xz5s/UQqRo62DEYI/AAAAAAAAXHI/oMbSzhgZ9ck/s1600/modernie-scan.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="68" src="http://1.bp.blogspot.com/-Cs4Vob3xz5s/UQqRo62DEYI/AAAAAAAAXHI/oMbSzhgZ9ck/s640/modernie-scan.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The analysis tool checks for things like...&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Checks that common JavaScript libraries are up-to-date&lt;/li&gt;
&lt;li&gt;Checks if a range of CSS vendor prefixes are used&lt;/li&gt;
&lt;li&gt;Checks if Responsive Web Design is used&lt;/li&gt;
&lt;li&gt;Checks if Touch browsing has been considered&lt;/li&gt;
&lt;li&gt;Checks if you are using Browser detection instead of Feature detection&lt;/li&gt;
&lt;li&gt;etc...&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
The nice thing about the tool is that it not only finds suggestions, but it also recommends ways to resolve the issues it finds. In addition it doesn't just point out IE specific stuff, but also about more generic concepts like using CSS3 vendor prefixes and to consider responsive web design.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-p32CgHJ8f24/UQqPBuMmtNI/AAAAAAAAXHA/2pgy5fSa2TA/s1600/logo-separate-big.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="100" src="http://4.bp.blogspot.com/-p32CgHJ8f24/UQqPBuMmtNI/AAAAAAAAXHA/2pgy5fSa2TA/s200/logo-separate-big.png" width="100" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h3&gt;Testing Tools&lt;/h3&gt;&lt;br /&gt;
Microsoft understands that not all developers use Windows when they develop and have Internet Explorer easily available in order to test. So, a special &lt;a href="http://www.modern.ie/virtualization-tools"&gt;3 month free testing account&lt;/a&gt; is available with BrowserStack.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-2xNdDGtRAMs/UQqaT2jZlbI/AAAAAAAAXHk/wInWH8O2OFE/s1600/Screen+Shot+2013-01-31+at+10.21.08+AM.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="241" src="http://2.bp.blogspot.com/-2xNdDGtRAMs/UQqaT2jZlbI/AAAAAAAAXHk/wInWH8O2OFE/s320/Screen+Shot+2013-01-31+at+10.21.08+AM.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;Not only is this a nice tool for Mac or Linux developers, but it is also nice for Windows users to test old version of IE or if you don't have Virtual Machines handy.&lt;br /&gt;
&lt;br /&gt;
You can also install some handy add-ons to &lt;a href="https://chrome.google.com/webstore/detail/test-ie/eldlkpeoddgbmpjlnpfblfpgodnojfjl/related"&gt;Chrome&lt;/a&gt; or &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/test-ie/"&gt;Firefox&lt;/a&gt; to make the testing experience with BrowserStack even better.&lt;br /&gt;
&lt;br /&gt;
In addition, Microsoft is providing &lt;a href="http://www.modern.ie/virtualization-tools"&gt;free Virtual Machine images&lt;/a&gt; for you to use if you want more control. Even though BrowserStack is awesome for a quick sanity check or to run unit tests, if you are trying to debug something having a local VM is optimal in those cases.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Video about modern.IE&lt;/h3&gt;&lt;br /&gt;
&lt;iframe allowfullscreen="" frameborder="0" height="360" src="http://www.youtube.com/embed/MH_Dao4FEfQ" width="640"&gt;&lt;/iframe&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/5992146909135005839/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/testing-for-internet-explorer-just-got.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5992146909135005839?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5992146909135005839?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/testing-for-internet-explorer-just-got.html" title="modern.IE - Analysis and Testing Tools for Web Developers" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-pf-2JD11LJo/UQqSiWkUA1I/AAAAAAAAXHQ/RyifmzbyOQ0/s72-c/modernie-crop-m.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DEUEQ3s7eSp7ImA9WhBTFk0.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-1796277564055003052</id><published>2013-01-29T00:05:00.000-06:00</published><updated>2013-02-11T12:10:02.501-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-11T12:10:02.501-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Yo dawg, I herd you like loops, so jQuery put a loop in your code</title><content type="html">&lt;a href="http://memegenerator.net/instance/33339848" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="258" src="http://1.bp.blogspot.com/-zAsVWpN4dFM/UPOO4gDupfI/AAAAAAAAWWU/wpN9tjWSf4Y/s400/yo-dawg-jquery-herd.png" width="400" /&gt;&lt;/a&gt;&lt;h3&gt;Do You Know When You Are Looping in jQuery?&lt;/h3&gt;&lt;br /&gt;
A common misunderstanding I see when looking at jQuery code is a lack of understanding about loops. &lt;br /&gt;
&lt;br /&gt;
Most developers seem to grok the &lt;code&gt;&lt;a href="http://api.jquery.com/each/"&gt;.each()&lt;/a&gt;&lt;/code&gt; method, but that can be both a good and a bad thing. &lt;br /&gt;
&lt;br /&gt;
It is important to know the difference between an Implicit Loop and an Explicit Loop.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Implicit Loops&lt;/h3&gt;&lt;br /&gt;
The following code snippet is something that you would typically see from a jQuery developer. You are probably aware of the "Find something, Do something" mentality of jQuery. The code first queries the DOM for all elements that have the &lt;code&gt;widget&lt;/code&gt; class and then jQuery proceeds to implicitly loop over all of the elements matching the query and adds the &lt;code&gt;highlight&lt;/code&gt; class.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4646532.js?file=implicit-loops.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Explicit Loops&lt;/h3&gt;&lt;br /&gt;
An explicit loop in jQuery is much more obvious. The code for the loop is visible via the &lt;code&gt;.each&lt;/code&gt; method. This is pretty straight forward and typically developers understand that there could be performance issues for any code inside the &lt;code&gt;.each&lt;/code&gt; loop.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4646532.js?file=explicit-loops.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;h3&gt;Indications of Confusion&lt;/h3&gt;&lt;br /&gt;
You can start to tell if a developer doesn't realize the different between implicit and explicit loops if you start to see something like the following code snippet. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4646532.js?file=confusion.js"&gt;&lt;/script&gt;&lt;br /&gt;
In this example there is no reason for using the &lt;code&gt;.each&lt;/code&gt; method because there was nothing inside of the loop that is unique. A simple implicit loop, like the following snippet, would have been sufficient. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4646532.js?file=confusion-fixed.js"&gt;&lt;/script&gt;&lt;br /&gt;
&lt;img src="http://s2.favim.com/orig/28/fruit-loops-yummy-Favim.com-235858.gif" style="float: right; padding: 0px 0px 15px 15px; width: 250px;" /&gt;&lt;h3&gt;Method Overloads&lt;/h3&gt;&lt;br /&gt;
Knowing about implicit loops also sheds some light of the following situation. &lt;br /&gt;
&lt;br /&gt;
In the following snippet of code jQuery is looping over the matches elements twice (once to change the color and a second time to change the font-size). &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4646532.js?file=slowness.js"&gt;&lt;/script&gt;&lt;br /&gt;
If you needed to write code similar to the previous, you could do something like the following instead and use the "overloaded" &lt;code&gt;.css&lt;/code&gt; method that takes an object containing the key/value pairs you wish to apply. &lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4646532.js?file=slowness-fixed.js"&gt;&lt;/script&gt;&lt;br /&gt;
It might seem like the above snippet is slower than the following, but when it comes down to it they are about the same speed. I tend to recommend the last snippet as it is cleaner and more flexible down the road as you can pass in a variable containing all your options. &lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;As a side note, it is preferable to use the &lt;code&gt;.addClass()&lt;/code&gt; / &lt;code&gt;.removeClass()&lt;/code&gt; / &lt;code&gt;.toggleClass()&lt;/code&gt; methods instead of the &lt;code&gt;.css()&lt;/code&gt; method to manipulate your elements unless you need to change their width/height/position/etc. The output of the &lt;code&gt;.css()&lt;/code&gt; method gets attached to the &lt;code&gt;style&lt;/code&gt; attribute of your element. The browser is highly optimized to deal with CSS classes and also whoever is maintaining will thank you for using classes instead of hardcoding style in your code.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Although these concepts may seem very basic, I often run across code that doesn't require an &lt;code&gt;.each&lt;/code&gt; method. It is helpful knowing some of these under the cover concepts. I hope you found it insightful. </content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/1796277564055003052/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/yo-dawg-i-herd-you-like-loops-so-jquery.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1796277564055003052?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1796277564055003052?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/yo-dawg-i-herd-you-like-loops-so-jquery.html" title="Yo dawg, I herd you like loops, so jQuery put a loop in your code" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-zAsVWpN4dFM/UPOO4gDupfI/AAAAAAAAWWU/wpN9tjWSf4Y/s72-c/yo-dawg-jquery-herd.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkUCSXs_cCp7ImA9WhBTGEg.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-4665768389853151756</id><published>2013-01-28T08:00:00.000-06:00</published><updated>2013-02-14T09:04:28.548-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-14T09:04:28.548-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript" /><category scheme="http://www.blogger.com/atom/ns#" term="CSS3" /><category scheme="http://www.blogger.com/atom/ns#" term="HTML5" /><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>Beginner HTML5, JavaScript, jQuery, Backbone, and CSS3 Resources</title><content type="html">&lt;h2&gt;A Beginner's Journey&lt;/h2&gt;&lt;br /&gt;
I was recently approached by someone at a .NET User Group about how to get started in HTML5, JavaScript, jQuery, CSS3, etc... The developer's primary background was writing thick client Windows applications. I figured the best place to start is to focus on the bare essentials and then work up to more advanced concepts and resources. I started to respond to the developer in an e-mail, but then I remembered what &lt;a href="http://twitter.com/shanselman"&gt;Scott Hanselman&lt;/a&gt; said in a recent &lt;a href="http://www.hanselman.com/blog/DoTheyDeserveTheGiftOfYourKeystrokes.aspx"&gt;post&lt;/a&gt; and &lt;a href="http://www.hanselman.com/blog/ItsNotWhatYouReadItsWhatYouIgnoreVideoOfScottHanselmansPersonalProductivityTips.aspx"&gt;video&lt;/a&gt; ...&lt;br /&gt;
&lt;br /&gt;
&lt;div class="alert alert-block"&gt;"Instead, consider writing a blog post or adding to a wiki with your keystrokes, then emailing the link to the original emailer." --Scott Hanselman&lt;/div&gt;&lt;br /&gt;
So, I decided to make this blog post for the developer and also for anyone else who may be interested in similar resources.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-kIG-7Foi-EU/UQNlQgx6dnI/AAAAAAAAW8s/S1dDruTF67Y/s1600/html5.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-kIG-7Foi-EU/UQNlQgx6dnI/AAAAAAAAW8s/S1dDruTF67Y/s200/html5.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;HTML5&lt;/h2&gt;&lt;br /&gt;
So, it is pretty obvious that you are going to need to learn HTML5 if you are doing to do front-end web development. From my experience most developers regardless of their language of choice know the basics of HTML. What they may or may not know are all the newer semantic tags, cross-browser tricks, and native JavaScript APIs. &lt;br /&gt;
&lt;br /&gt;
There is plenty to learn in HTML5 without getting into the JavaScript APIs just yet. Once you learn JavaScript and feel comfortable in it, that may be the best time to tackle topics such as Geolocation, Web Sockets, Canvas, IndexDB, Web Workers, etc...&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://html5doctor.com/html5-for-web-developers/"&gt;HTML5 for Web Developers&lt;/a&gt; &lt;span class="label label-inverse"&gt;API&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://coding.smashingmagazine.com/2011/11/18/html5-semantics/"&gt;HTML5 Semantics&lt;/a&gt; by Bruce Lawson &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.alistapart.com/articles/semanticsinhtml5/"&gt;Semantics in HTML5&lt;/a&gt; by John Allsopp &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://html5doctor.com/designing-a-blog-with-html5/"&gt;Designing a blog with HTML5&lt;/a&gt; by Bruce Lawson &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.html5rocks.com/en/tutorials/"&gt;HTML5 Rocks Tutorials&lt;/a&gt; &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://movethewebforward.org/"&gt;Move the Web Forwards&lt;/a&gt; &lt;span class="label label-misc"&gt;Misc&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://html5doctor.com/"&gt;HTML5 Doctor&lt;/a&gt; &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.w3.org/TR/html-markup/Overview.html#toc-full"&gt;HTML5 Specification&lt;/a&gt; &lt;span class="label label-inverse"&gt;API&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://diveintohtml5.info/"&gt;Dive Into HTML5&lt;/a&gt; by Mark Pilgrim &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-2exPcbRhYtA/UQNlZELLW8I/AAAAAAAAW80/xE4EeqWUyts/s1600/js.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-2exPcbRhYtA/UQNlZELLW8I/AAAAAAAAW80/xE4EeqWUyts/s200/js.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;JavaScript&lt;/h2&gt;&lt;br /&gt;
Even if you think you know JavaScript it might behoove you to go back and learn it from the beginning. A common danger is that developers think it looks just like their back-end language of choice (C, C++, C#, or Java) that they don't invest time to learn how it is different.&lt;br /&gt;
&lt;br /&gt;
JavaScript is a dynamic and functional language, which is considerably different than C# or Java for example. So, please take your time and pick up the language. If you don't learn it appropriately you will invariably run into barriers down the road due to lack of understanding.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://eloquentjavascript.net/"&gt;Eloquent JavaScript&lt;/a&gt; by Marijn Haverbeke &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.javascriptenlightenment.com/"&gt;JavaScript Enlightenment&lt;/a&gt; by Cody Lindley &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://shop.oreilly.com/product/9780596517748.do"&gt;JavaScript: The Good Parts&lt;/a&gt; by Douglas Crockford &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-paid"&gt;Paid&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/Professional-JavaScript-Developers-Wrox-Guides/dp/0764579088"&gt;Professional JavaScript for Web Developers&lt;/a&gt; by Nicholas Zakas &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-paid"&gt;Paid&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.reybango.com/2010/12/15/what-to-read-to-get-up-to-speed-in-javascript/"&gt;What to Read to Get Up to Speed in JavaScript&lt;/a&gt; by &lt;a href="http://twitter.com/reybango"&gt;Rey Bango&lt;/a&gt; &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://learn.appendto.com/"&gt;Learn jQuery &amp;amp; JavaScript for free&lt;/a&gt; by appendTo &lt;span class="label label-warning"&gt;Video&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-4V_m-KWKXZc/UQRY3BgybRI/AAAAAAAAW90/sDDS3iM_tT4/s1600/jquery-logo-150x150.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-4V_m-KWKXZc/UQRY3BgybRI/AAAAAAAAW90/sDDS3iM_tT4/s200/jquery-logo-150x150.jpg" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;jQuery&lt;/h2&gt;&lt;br /&gt;
The jQuery library has been around for several years and has catapulted as one of the most used tools in the web developer's belt. The reason for its vast usage is that it solves many of the cross-browser issues that creep up during development. The library is popular for both web developers and web designers. The community around jQuery is amazing and there are tons of jQuery plugins to choose from. &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://api.jquery.com/"&gt;jQuery API&lt;/a&gt; &lt;span class="label label-inverse"&gt;API&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://plugins.jquery.com/"&gt;jQuery Plugin Repository&lt;/a&gt; &lt;span class="label label-success"&gt;Library&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://learn.appendto.com/"&gt;Learn jQuery &amp;amp; JavaScript for free&lt;/a&gt; by appendTo &lt;span class="label label-warning"&gt;Video&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://jqfundamentals.com/"&gt;jQuery Fundamentals&lt;/a&gt; by Bocoup &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/articles/news/learn-jquery-in-30-days/"&gt;Learn jQuery in 30 Days&lt;/a&gt; by NETTUTS &lt;span class="label label-warning"&gt;Video&lt;/span&gt; &lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-xdZxDAStMTc/UQRY8nCnmuI/AAAAAAAAW98/sqp4pXNrlE8/s1600/Backbone_logo_logo_only.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://2.bp.blogspot.com/-xdZxDAStMTc/UQRY8nCnmuI/AAAAAAAAW98/sqp4pXNrlE8/s200/Backbone_logo_logo_only.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;Backbone.js&lt;/h2&gt;&lt;br /&gt;
If you find yourself writing more and more JavaScript and jQuery then you may want to consider picking up Backbone.js to help you organize your web application. This library is also a great fit for Single Page Applications (SPA). Backbone.js uses the familiar MVC/MVP concepts of Models, Collections, Views, and Routers. In addition there is a nice Event model, History support, and a Sync mechanism. The community for Backbone.js is also very large and you can find many extensions and plugins to fit your needs.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://backbonejs.org/"&gt;Backbone.js API&lt;/a&gt; &lt;span class="label label-inverse"&gt;API&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://backbonejs.org/docs/backbone.html"&gt;Annotated Backbone.js Code&lt;/a&gt; &lt;span class="label label-inverse"&gt;API&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/documentcloud/backbone/wiki/Extensions,-Plugins,-Resources"&gt;Backbone Extensions, Plugins, &amp;amp; Resources&lt;/a&gt; &lt;span class="label label-success"&gt;Library&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tbranyen/backbone-boilerplate"&gt;Backbone Boilerplate&lt;/a&gt; &lt;span class="label label-misc"&gt;Misc&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/addyosmani/backbone-fundamentals"&gt;Backbone Fundamentals eBook&lt;/a&gt; by Addy Osmani &lt;span class="label label-important"&gt;Book&lt;/span&gt; &lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://peepcode.com/products/backbone-js"&gt;Peep Code: Backbone.js Video Series&lt;/a&gt; by Geoffery Grosenbach and David Goodlad &lt;span class="label label-warning"&gt;Video&lt;/span&gt; &lt;span class="label label-paid"&gt;Paid&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://pragprog.com/screencasts/v-dback/hands-on-backbone-js"&gt;The Pragmatic Bookshelf: Hands-on Backbone.js&lt;/a&gt; by Derick Bailey &lt;span class="label label-warning"&gt;Video&lt;/span&gt; &lt;span class="label label-paid"&gt;Paid&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://backbonescreencasts.com/"&gt;Backbone.js Screencasts&lt;/a&gt; by Joey Beninghove &lt;span class="label label-warning"&gt;Video&lt;/span&gt; &lt;span class="label label-paid"&gt;Paid&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.pluralsight.com/training/Courses/TableOfContents/backbone-fundamentals"&gt;Pluralsight: Backbone.js Fundamentals&lt;/a&gt; by Liam McLennan &lt;span class="label label-warning"&gt;Video&lt;/span&gt; &lt;span class="label label-paid"&gt;Paid&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://codular.com/starting-with-backbone"&gt;The Skinny on BackboneJS&lt;/a&gt; by &lt;a href="http://twitter.com/benhowdle"&gt;Ben Howdle&lt;/a&gt; &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://backbonetutorials.com/"&gt;Backbone Tutorials&lt;/a&gt; &lt;span class="label label-misc"&gt;Misc&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tag/backbone/"&gt;Backbone.js Tutorials&lt;/a&gt; via Nettuts  &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://javascriptplayground.com/blog/category/backbonejs"&gt;Exploring Backbone.js Series&lt;/a&gt; by &lt;a href="http://twitter.com/jack_franklin"&gt;Jack Franklin&lt;/a&gt; &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-YTiH-WSka84/UQNlvIwQZsI/AAAAAAAAW9E/7FzoNxea6X4/s1600/css3-logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://1.bp.blogspot.com/-YTiH-WSka84/UQNlvIwQZsI/AAAAAAAAW9E/7FzoNxea6X4/s200/css3-logo.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;CSS3&lt;/h2&gt;&lt;br /&gt;
You may or may not have experience with CSS. Brushing up on CSS concepts would be a good thing. If you already feed proficient at CSS1-2, then you should pick up CSS3 as well. A lot of features have been added recently that is in most modern browsers. There are many things that you can do in CSS3 now where you used to use JavaScript or custom images.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.amazon.com/Bulletproof-Web-Design-flexibility-protecting/dp/0321808355"&gt;Bulletproof Web Design&lt;/a&gt; &lt;span class="label label-important"&gt;Book&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/CSS/Getting_Started"&gt;Getting Started (CSS Tutorial)&lt;/a&gt; by MDN &lt;span class="label"&gt;Wiki&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://coding.smashingmagazine.com/2009/10/05/mastering-css-coding-getting-started/"&gt;Mastering CSS Coding: Getting Started&lt;/a&gt; by Soh Tanaka &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/"&gt;The 30 CSS Selectors you Must Memorize&lt;/a&gt; by Jeffrey Way &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://css3please.com/"&gt;CSS3 Please&lt;/a&gt; &lt;span class="label label-info"&gt;Tool&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://net.tutsplus.com/sessions/css3-mastery/"&gt;CSS3 Mastery&lt;/a&gt; &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://csslint.net/"&gt;CSS Lint&lt;/a&gt; &lt;span class="label label-info"&gt;Tool&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://csscomb.com/"&gt;CSS Comb&lt;/a&gt; &lt;span class="label label-info"&gt;Tool&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-SaZ_VRTTIPM/UQNmq-omgNI/AAAAAAAAW9Y/Y5oUTvEdI6Q/s1600/Modernizr+2+Logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="96" src="http://2.bp.blogspot.com/-SaZ_VRTTIPM/UQNmq-omgNI/AAAAAAAAW9Y/Y5oUTvEdI6Q/s200/Modernizr+2+Logo.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;Feature Detection&lt;/h2&gt;&lt;br /&gt;
Inevitably you'll need to support browsers that don't support the native feature you are trying to use. Thankfully you can use Feature Detection to determine if the browser you are in implements that feature and if it doesn't then you can provide functionality to mimic that feature (a.k.a. a polyfill or shim).&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://modernizr.com/"&gt;Modernizr&lt;/a&gt; &lt;span class="label label-success"&gt;Library&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://html5please.com/"&gt;HTML5 Please&lt;/a&gt; &lt;span class="label label-info"&gt;Tool&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills"&gt;HTML5 Cross Browser Polyfills&lt;/a&gt; &lt;span class="label label-success"&gt;Library&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://caniuse.com/"&gt;Can I Use?&lt;/a&gt; &lt;span class="label label-info"&gt;Tool&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-IfWNFdkOKFA/UQNl03cte6I/AAAAAAAAW9M/B-KxL06DgRk/s1600/Responsive_Web_Design_Logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://3.bp.blogspot.com/-IfWNFdkOKFA/UQNl03cte6I/AAAAAAAAW9M/B-KxL06DgRk/s200/Responsive_Web_Design_Logo.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2&gt;Responsive Web Design&lt;/h2&gt;&lt;br /&gt;
Instead of implementing a different UI for mobile devices, tablets, and desktop browsers you can use responsive web design techniques to provide one experience that restructures the UI according to its size.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Resources&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.alistapart.com/articles/responsive-web-design/"&gt;Responsive Web Design&lt;/a&gt; by Ethan Marcotte &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://coding.smashingmagazine.com/2011/01/12/guidelines-for-responsive-web-design/#more-75660"&gt;Responsive Web Design: What It Is and How To Use It&lt;/a&gt; by Kayla Knight &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://uxdesign.smashingmagazine.com/2012/05/30/design-process-responsive-age/"&gt;Design Process In The Responsive Age&lt;/a&gt; by Drew Clemens &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://mobile.smashingmagazine.com/2011/07/22/responsive-web-design-techniques-tools-and-design-strategies/"&gt;Responsive Web Design Techniques, Tools and Design Strategies&lt;/a&gt; by Smashing Editorial &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;br /&gt;
Hopefully the above resources will get you started in your transition to front-end web development. There is a lot to learn, but it is an exciting space that changes frequently. Having a desire to learn is a good trait to have in this field. &lt;br /&gt;
&lt;br /&gt;
If you have any resources that you think I missed please add them in the comments and I'll try to update the lists above if I think they are appropriate. &lt;br /&gt;
&lt;br /&gt;
&lt;link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet"&gt;&lt;/link&gt;&lt;br /&gt;
&lt;style&gt;
.label-demo { background-color: #6C530C; }
.label-misc { background-color: #A9059B; }
.label-free { background-color: #123FA6; }
.label-paid { background-color: #780D0D; }
h2.title, h2.date-header, .widget h2 { font-size: 13px; line-height: 20px; }
.content-outer { margin: 0px auto; }
.gsc-input { margin-bottom: 0px !important; }
&lt;/style&gt;&lt;br /&gt;
&lt;!-- &lt;span class="label"&gt;Blog&lt;/span&gt;&lt;span class="label label-success"&gt;Library&lt;/span&gt;&lt;br /&gt;
&lt;span class="label label-warning"&gt;Video&lt;/span&gt;&lt;span class="label label-important"&gt;Book&lt;/span&gt;&lt;span class="label label-info"&gt;Tool&lt;/span&gt;&lt;br /&gt;
&lt;span class="label label-inverse"&gt;API&lt;/span&gt;&lt;span class="label label-misc"&gt;Misc&lt;/span&gt;&lt;span class="label label-free"&gt;Free&lt;/span&gt;&lt;span class="label label-paid"&gt;Paid&lt;/span&gt; --&gt;</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/4665768389853151756/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/beginner-html5-javascript-jquery.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4665768389853151756?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/4665768389853151756?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/beginner-html5-javascript-jquery.html" title="Beginner HTML5, JavaScript, jQuery, Backbone, and CSS3 Resources" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-kIG-7Foi-EU/UQNlQgx6dnI/AAAAAAAAW8s/S1dDruTF67Y/s72-c/html5.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;Ck8ARX48cCp7ImA9WhNbGEQ.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-7132249118053484141</id><published>2013-01-22T00:30:00.000-06:00</published><updated>2013-01-22T15:40:44.078-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-22T15:40:44.078-06:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="jQuery" /><title>The 5 Emotional Stages of a jQuery Upgrade</title><content type="html">&lt;blockquote&gt;The following post contains a emotional filled dialog between fictitious front-end developers "Frank Fowler" and "Mike Morris". In this drama filled exchange Frank decides to upgrade his current project to the latest jQuery release.&lt;/blockquote&gt;&lt;br /&gt;
&lt;iframe width="640" height="360" src="http://www.youtube.com/embed/wehTkNEfPt8" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Sadness&lt;/h3&gt;&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Ahh man, I just saw that &lt;a href="http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/"&gt;jQuery 1.9&lt;/a&gt; was released. Too bad my current project is still using the 1.8.3 release. &lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Ohh bummer, sorry to hear that. I tested out the beta release of 1.9 that came out about a month ago and didn't have any issues.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Really!?! Sign... I wish I could upgrade. I don't know if I can convince my boss to invest the time to upgrade and staying on an older version makes me a little sad.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Fear&lt;/h3&gt;&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; You might consider upgrading. They've fixed lots of bugs, enhanced CSS3 support, and added several new features.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; I don't know. It is a big project and I don't know if I can risk all the extra testing. I'm glad that it worked out for you, but I may just have to stay on this old version while everybody else upgrades. &lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Frank, an upgrade shouldn't be so bad. The jQuery team does a good job outlining the change log and they have over 6000 unit tests to ensure quality over a suite of browsers.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Yeah, I guess you are right, but it is such a huge project. What if something goes wrong? Surely something will go wrong, right? I'm fearful that I won't be able to figure it out if there is an issue. &lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Well, it wouldn't hurt trying would it?&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; I guess you are right. Lets go head and give it a try.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Anger&lt;/h3&gt;&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Okay, I just added a reference to the jQuery CDN for the 1.9 release to my project. Here goes nothing...&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; So, how did it go?&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Huh... WHAT!?! Nothing even works anymore! I knew I shouldn't have upgraded.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Well, what exactly is breaking?&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Like I said, nothing works! What did jQuery do to this release? Are they trying to hurt the development community? The last version worked just fine for me. I don't know if I can trust this project anymore.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Shame&lt;/h3&gt;&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Now now, lets take a look at this together. Does your application use some of the features that jQuery deprecated?&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; What!?! Deprecated? Umm, well I don't know. When did they deprecate features?&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; A while back jQuery mentioned they were going to deprecate features like the &lt;code&gt;.live()&lt;/code&gt; method and &lt;code&gt;.browser&lt;/code&gt; sniffing.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Ohh, I guess I didn't realize that. Maybe I should have read the blog post release notes more thoroughly :(&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Yeah, even though they deprecated those features jQuery hadn't removed them until the 1.9 release. So, maybe that is why some of your code is broken. I know you used to use &lt;code&gt;.live()&lt;/code&gt;. Did you change your &lt;code&gt;.live()&lt;/code&gt; to use the new &lt;code&gt;.on()&lt;/code&gt; method?&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Yeah, I never did switch to the new &lt;code&gt;.on()&lt;/code&gt; method that they added a while back and the application does do some sniffing using the &lt;code&gt;$.browser&lt;/code&gt; object. So, I guess that means I won't be able to upgrade to the 1.9 release.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Gladness&lt;/h3&gt;&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Ohh, no! The jQuery team planning for issues like this so they went ahead and put all of the removed deprecated features into a &lt;a href="https://github.com/jquery/jquery-migrate/blob/master/warnings.md"&gt;migration plugin&lt;/a&gt; in case you still need it. That way you can use the new stuff without having to immediately refactor your existing code. The idea is that you can slowly refactor as needed.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Really!?! Wow, that is so easy. Let me guess, that was explained in the release notes too? &lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; Yep ;) No probably man, it happens. Now don't get me wrong there are some releases where some bugs are introduced in a major release, but they are usually found pretty quickly and a minor release comes out shortly after. However, with this particular issue there was a planned workaround.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Frank:&lt;/em&gt; Why looky there, I just applied the migration plugin and now my app is working as expected. Thanks for your help Mike.&lt;br /&gt;
&lt;br /&gt;
&lt;em&gt;Mike:&lt;/em&gt; I didn't really do anything, it was the jQuery core members... you should thank them ;)&lt;br /&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/7132249118053484141/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/the-5-emotional-stages-of-jquery-upgrade.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/7132249118053484141?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/7132249118053484141?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/the-5-emotional-stages-of-jquery-upgrade.html" title="The 5 Emotional Stages of a jQuery Upgrade" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://img.youtube.com/vi/wehTkNEfPt8/default.jpg" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;D0UMQXw-fip7ImA9WhNbE0k.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-5547976532547292816</id><published>2013-01-16T00:22:00.002-06:00</published><updated>2013-01-16T08:08:00.256-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-16T08:08:00.256-06:00</app:edited><title>The Magic of the jQuery 1.9 Source Map</title><content type="html">&lt;h3&gt;jQuery 1.9 Supports Source Maps&lt;/h3&gt;&lt;br /&gt;
You may have noticed that the &lt;a href="http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/"&gt;1.9 version of jQuery&lt;/a&gt; was released yesterday. One of the most excited pieces of the version is support for Source Maps! &lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;&lt;a href="http://3.bp.blogspot.com/-_PymUzdleeI/UPY4RqKN4rI/AAAAAAAAWbA/T_-uLvZrQN8/s1600/dev-tools-enable-source-maps-cropped.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-_PymUzdleeI/UPY4RqKN4rI/AAAAAAAAWbA/T_-uLvZrQN8/s400/dev-tools-enable-source-maps-cropped.png" width="306" /&gt;&lt;/a&gt;What are Source Maps?&lt;/h3&gt;&lt;br /&gt;
What is a Source Map? Well, it is a generic way to translate one script format into another. In jQuery's case, it is mapping the minified version of jQuery against the un-minified version. Why would you want to do this? The value is that when you encounter a bug in your production code you can debug against code that doesn't look like a mangled mess! &lt;br /&gt;
&lt;br /&gt;
You can find out much more about Source Maps from &lt;a href="http://twitter.comryanseddon"&gt;Ryan Seddon&lt;/a&gt;'s HTML Rocks Tutorial titled &lt;a href="http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/"&gt;Introduction to JavaScript Source Maps&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Another slightly different example of for Source Maps is for CoffeeScript. The official CoffeeScript language doesn't support Source Maps as of yet, but there is a rewrite of the project called &lt;a href="https://github.com/michaelficarra/CoffeeScriptRedux/"&gt;CoffeeScript Redux&lt;/a&gt; that does support them. That means you can debug through CoffeeScript code in your dev tools and it will map to the underlying JavaScript code. For more information about this check out Ryan Florence's article titled &lt;a href="http://ryanflorence.com/2012/coffeescript-source-maps/"&gt;CoffeeScript Source Maps&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Enabling Source Maps in Chrome&lt;/h3&gt;&lt;br /&gt;
In stable release of Google Chrome there is a setting in its dev tools to "Enable source maps". You will need to check this option in order to use this feature.&lt;br /&gt;
&lt;br /&gt;
Mozilla Firefox is working on providing Source Map support, but as of yet Google Chrome is the browser to use for this feature.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Add the Minified jQuery 1.9 to Your Project&lt;/h3&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/--hlNMOkOpHY/UPY_mM3dQrI/AAAAAAAAWbs/gvpF-Lmn-Ls/s1600/dev-tools-jsfiddle-cropped-600-arrow.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/--hlNMOkOpHY/UPY_mM3dQrI/AAAAAAAAWbs/gvpF-Lmn-Ls/s1600/dev-tools-jsfiddle-cropped-600-arrow.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The minified version of jQuery 1.9 has a special directive at the bottom that tells Google Chrome what Source Map to use when debugging. The end of the minified file looks like the following...&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/4544982.js"&gt;&lt;/script&gt;&lt;br /&gt;
In order to get the Source Map to work you need to make sure the value of &lt;code&gt;sourceMappingURL&lt;/code&gt; exists on your server or locally. If you are using the jQuery CDN then this is already setup for you. &lt;br /&gt;
&lt;br /&gt;
The Google CDN is now hosting jQuery 1.9 and its map file as well. It isn't listed on their &lt;a href="https://developers.google.com/speed/libraries/devguide#jquery"&gt;main CDN page&lt;/a&gt;, but you can access it directly &lt;a href="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"&gt;http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Debugging Your Project&lt;/h3&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-tT_3EOR6aSE/UPZCKeiCo6I/AAAAAAAAWcA/AGFe_Bql-DM/s1600/dev-tools-break-point-cropped.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-tT_3EOR6aSE/UPZCKeiCo6I/AAAAAAAAWcA/AGFe_Bql-DM/s1600/dev-tools-break-point-cropped.png" /&gt;&lt;/a&gt;&lt;/div&gt;Once you've completed the above steps then using Source Maps is simple. All you have to do is set a break point, like you would normally, and then debug into it.&lt;br /&gt;
&lt;br /&gt;
For example, on the left I set a breakpoint on the &lt;code&gt;addClass&lt;/code&gt; statement. Once I debug into that statement I get dropped into the unminfied version of jQuery NOT the minified version that I included! &lt;br /&gt;
&lt;br /&gt;
Browsers have had a "Pretty print" feature for a while which has formatted minifed script files, but Source Maps brings that to a whole new level!&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-AGbOU8L6ga8/UPZC61g3YzI/AAAAAAAAWcI/6j0sGucWhZE/s1600/dev-tools-into-mapped-jquery-cropped.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-AGbOU8L6ga8/UPZC61g3YzI/AAAAAAAAWcI/6j0sGucWhZE/s1600/dev-tools-into-mapped-jquery-cropped.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;&lt;br /&gt;
Source Maps are a powerful new feature of Google Chrome and I look forward to it coming to other browsers in the near future. Being able to debug through minified code could make tracking down production bugs a much easier process.&lt;br /&gt;
</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/5547976532547292816/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/the-magic-of-jquery-source-map.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5547976532547292816?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/5547976532547292816?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/the-magic-of-jquery-source-map.html" title="The Magic of the jQuery 1.9 Source Map" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-_PymUzdleeI/UPY4RqKN4rI/AAAAAAAAWbA/T_-uLvZrQN8/s72-c/dev-tools-enable-source-maps-cropped.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;C0cBRXc8eSp7ImA9WhNbEko.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-6909392194784762225</id><published>2013-01-15T11:28:00.002-06:00</published><updated>2013-01-15T11:30:54.971-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-01-15T11:30:54.971-06:00</app:edited><title>Don't Hot-fix IE6-8, Upgrade to IE9-10 Instead</title><content type="html">&lt;h3&gt;&lt;a href="http://4.bp.blogspot.com/-L1tyxDRGPsM/UPVpEW-fWDI/AAAAAAAAWag/lV7vYJJ83VY/s1600/internet-explorer-10-for-windows-7-21-535x535.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="200" src="http://4.bp.blogspot.com/-L1tyxDRGPsM/UPVpEW-fWDI/AAAAAAAAWag/lV7vYJJ83VY/s200/internet-explorer-10-for-windows-7-21-535x535.png" width="200" /&gt;&lt;/a&gt;Critical Internet Explorer 6-8 Hot-fix&lt;/h3&gt;&lt;br /&gt;
You may have seen the buzz yesterday about the &lt;a href="http://blogs.msdn.com/b/ie/archive/2013/01/14/microsoft-security-bulletin-ms13-008-critical.aspx"&gt;Critical Microsoft Security Hot-fix (MS13-008)&lt;/a&gt;. The hot-fix applies to a security issue in Internet Explorer versions 6 through 8. Newer version of IE (9 and 10) are not in danger.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Upgrade to IE9-10 Instead&lt;/h3&gt;&lt;br /&gt;
You could apply the above hot-fix to your existing old version of Internet Explorer, but why? Why not go ahead and &lt;a href="http://msdn.microsoft.com/en-us/ie/aa740471.aspx"&gt;upgrade to IE9 or IE10&lt;/a&gt;?&lt;br /&gt;
&lt;br /&gt;
Not only will you get more features and a faster browser, but you will also be pushing the web forward. Developers will thank you for having one less oldIE browser to support. The nice thing about IE9-10 is that they follow web standards, which means code that is written to follow standards and practices should just work in IE9-10 and other modern browsers.&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;Note: IE10 is only available as a Preview release on Windows 7 as of now. A full RTM release of IE10 should be released in the near future. Be warned, if you do install IE10 Preview on Win7 it will replace your IE9 browser.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Others are dropping oldIE (IE6-8)&lt;/h3&gt;&lt;br /&gt;
Others are following suite. &lt;a href="http://techcrunch.com/2012/09/14/google-apps-says-goodbye-to-internet-explorer-pulls-support-for-the-browser/"&gt;Google Apps&lt;/a&gt; recently decided to drop oldIE a while back and only support IE9+ and other modern browsers. &lt;br /&gt;
&lt;br /&gt;
In addition popular JavaScript libraries like jQuery are now dropping oldIE support in their &lt;a href="http://blog.jquery.com/2013/01/15/jquery-1-9-final-jquery-2-0-beta-migrate-final-released/"&gt;upcoming 2.0 release&lt;/a&gt;. After jQuery dropped oldIE support an interesting realization came about. Here is a quote from the jQuery Blog...&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;"jQuery 2.0 now has more patches and shims for Chrome, Safari, and Firefox than for Internet Explorer!" -- &lt;a href="http://blog.jquery.com/2013/01/14/the-state-of-jquery-2013/"&gt;http://blog.jquery.com/2013/01/14/the-state-of-jquery-2013&lt;/a&gt;&lt;/blockquote&gt;&lt;br /&gt;
So, what are you waiting for? Upgrade to a &lt;a href="http://msdn.microsoft.com/en-us/ie/aa740471.aspx"&gt;new version of IE&lt;/a&gt; today!</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/6909392194784762225/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/dont-hot-fix-ie6-8-upgrade-to-ie9-10.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/6909392194784762225?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/6909392194784762225?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/dont-hot-fix-ie6-8-upgrade-to-ie9-10.html" title="Don't Hot-fix IE6-8, Upgrade to IE9-10 Instead" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-L1tyxDRGPsM/UPVpEW-fWDI/AAAAAAAAWag/lV7vYJJ83VY/s72-c/internet-explorer-10-for-windows-7-21-535x535.png" height="72" width="72" /><thr:total>0</thr:total></entry><entry gd:etag="W/&quot;DkQFRnwzcSp7ImA9WhBTEEo.&quot;"><id>tag:blogger.com,1999:blog-30404818.post-1911273088003891142</id><published>2013-01-09T00:06:00.000-06:00</published><updated>2013-02-05T08:25:17.289-06:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-02-05T08:25:17.289-06:00</app:edited><title>Does Browser Sniffing Still Have a Place?</title><content type="html">&lt;h3&gt;Why and How Did We Use Browser Sniffing?&lt;/h3&gt;&lt;br /&gt;
For a long time browser sniffing was the way developers tested for various browsers and as a result used a different API or feature set. You can always manually detect by using the &lt;code&gt;navigator.userAgent&lt;/code&gt;, but making sense of it can be difficult considering the vast amount of &lt;a href="http://www.useragentstring.com/pages/useragentstring.php"&gt;userAgent combinations&lt;/a&gt;. Some libraries were developed to assit the developer in making sense of the userAgent. A detect library can be found from &lt;a href="http://www.quirksmode.org/js/detect.html"&gt;QuirksMode&lt;/a&gt; and &lt;a href="http://api.jquery.com/jQuery.browser/"&gt;jQuery&lt;/a&gt; also provides the &lt;code&gt;browser&lt;/code&gt; object with some sniffing information.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Problems with Browser Sniffing&lt;/h3&gt;&lt;br /&gt;
As you are probably aware, browser sniffing can be problematic and is the reason that some websites don't work properly cross-browser or in new versions of browsers.&lt;br /&gt;
&lt;br /&gt;
A simple example of where a browser sniff can break down is the following code snippet detecting for IE. The code should check if the browser is IE and if the version is 8 or greater.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4490679.js?file=browser-sniffing.js"&gt;&lt;/script&gt;&lt;br /&gt;
The code snippet works just fine in versions of IE 1-9, but breaks for IE10 because the regular expression doesn't account for multiple digits.&lt;br /&gt;
&lt;br /&gt;
You can review many of the bad reasons why you shouldn't browser sniff from the following resources&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.sitepoint.com/why-browser-sniffing-stinks/"&gt;Why Browser Sniffing Stinks&lt;/a&gt; by&amp;nbsp;&lt;a class="g-profile" href="http://plus.google.com/116685695906002348712" target="_blank"&gt;+Craig Buckler&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://css-tricks.com/browser-detection-is-bad/"&gt;Browser Detection is Bad&lt;/a&gt; by&amp;nbsp;&lt;a class="g-profile" href="http://plus.google.com/101987072260327250694" target="_blank"&gt;+Chris Coyier&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;blockquote&gt;Note: I mentioned above that jQuery has a &lt;code&gt;browser&lt;/code&gt; object, but that feature is deprecated and you shouldn't use it anymore. Also the detect script I mentioned above also has a blurb about using object detection instead of browser sniffing.&lt;/blockquote&gt;&lt;br /&gt;
&lt;h3&gt;Use Feature Detection Instead&lt;/h3&gt;&lt;br /&gt;
Feature Detection is the&amp;nbsp;preferred&amp;nbsp;way to determine the functionality of a browser and to respond accordingly and we've seen that&amp;nbsp;technique&amp;nbsp;used in many libraries such as &lt;a href="http://modernizr.com/"&gt;Modernizr&lt;/a&gt; and more.&lt;br /&gt;
&lt;br /&gt;
An example of feature detection could look something like the following.&lt;br /&gt;
&lt;br /&gt;
&lt;script src="https://gist.github.com/elijahmanor/4490679.js?file=feature-detection.js"&gt;&lt;/script&gt;&lt;br /&gt;
You can find nice polyfills or shims for HTML5 features from the &lt;a href="http://html5please.com/"&gt;HTML5 Please&lt;/a&gt; website and the &lt;a href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills"&gt;HTML5 Cross Browser Polyfills&lt;/a&gt; wiki from the Modernizr repository.&lt;br /&gt;
&lt;br /&gt;
If you are interested in finding out more about Modernizr or on how to make your own feature detections I'd encourage you to check out the following resources&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Polyfilling the Gaps &lt;a href="http://blip.tv/jsconfeu/lea-verou-polyfilling-the-gaps-5668145"&gt;video&lt;/a&gt;&amp;nbsp;&amp;amp; &lt;a href="http://lea.verou.me/polyfilling-the-gaps/"&gt;slides&lt;/a&gt;&amp;nbsp;by&amp;nbsp;&lt;a class="g-profile" href="http://plus.google.com/105591642938690900060" target="_blank"&gt;+Lea Verou&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://addyosmani.com/blog/polyfilling-the-html5-gaps/"&gt;PolyFilling the HTML5 Gaps with JavaScript&lt;/a&gt; by&amp;nbsp;&lt;a class="g-profile" href="http://plus.google.com/115133653231679625609" target="_blank"&gt;+Addy Osmani&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.netmagazine.com/features/writing-your-own-cross-browser-polyfills"&gt;Writing Your Own Cross Browser Polyfills&lt;/a&gt;&amp;nbsp;by&amp;nbsp;&lt;a class="g-profile" href="http://plus.google.com/115133653231679625609" target="_blank"&gt;+Addy Osmani&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;h3&gt;Does Browser Sniffing Still Have a Place?&lt;/h3&gt;&lt;br /&gt;
I recently became curious as to when browser sniffing might ever be acceptable. I mean, surely there must be a valid use case even if it isn't pretty. So, I went on a search on Twitter and I also polled some of my close developer friends on their thoughts. The following is a list of my findings.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Valid Use Cases for Browser Sniffing&lt;/h3&gt;&lt;br /&gt;
I've found the following use cases justifiable reasons to use browser sniffing. &lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Target specific content to platform a such as Mac or Win download. An example may be a Download link for multi-platform systems.&lt;/li&gt;
&lt;li&gt;Gather analytic information for marketing purposes. An example may be getting desktop, tablet, and mobile statistics from users.&lt;/li&gt;
&lt;li&gt;Determining if a user is on a particular platform in order to pin their application to the user's home or start screen. An example may be an iOS and showing a tooltip to add the mobile app to the home screen.&lt;/li&gt;
&lt;li&gt;In some cases Feature Detection isn't sufficient or there is no way to determine a certain state or behavior. In that case browser sniffing may need to be used. An example of this is in the &lt;a href="https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js"&gt;history.js&lt;/a&gt; detection in the Modernizr library.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Do you have any other use cases that you've seen or used that you feel are valid reasons to use browser sniffing? I'd be interested in hearing them.</content><link rel="replies" type="application/atom+xml" href="http://www.elijahmanor.com/feeds/1911273088003891142/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://www.elijahmanor.com/2013/01/does-browser-sniffing-still-have-place.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1911273088003891142?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/30404818/posts/default/1911273088003891142?v=2" /><link rel="alternate" type="text/html" href="http://www.elijahmanor.com/2013/01/does-browser-sniffing-still-have-place.html" title="Does Browser Sniffing Still Have a Place?" /><author><name>Elijah Manor</name><uri>https://plus.google.com/110944993173615692737</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh4.googleusercontent.com/-AtW_qomCJAo/AAAAAAAAAAI/AAAAAAAAWQc/whjy56PIj34/s512-c/photo.jpg" /></author><thr:total>0</thr:total></entry></feed>
