<?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:feedburner="http://rssnamespace.org/feedburner/ext/1.0">

  <title><![CDATA[Alex Sexton]]></title>
  
  <link href="http://alexsexton.com/" />
  <updated>2012-04-11T14:52:03-05:00</updated>
  <id>http://alexsexton.com/</id>
  <author>
    <name><![CDATA[Alex Sexton]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/AlexSexton" /><feedburner:info uri="alexsexton" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title type="html"><![CDATA[Third Party Front-end Performance]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/hTbAum7Q22Y/" />
    <updated>2012-04-11T14:36:00-05:00</updated>
    <id>http://alexsexton.com/blog/2012/04/third-party-front-end-performance-part-1</id>
    <content type="html">&lt;p&gt;I work for a company called &lt;a href="http://developer.bazaarvoice.com/"&gt;Bazaarvoice&lt;/a&gt;. Our core products (Ratings and Reviews is our biggest) are all implemented as third party javascript applications. We are white-label, so you don&amp;#8217;t see a ton of our brand around, but we power the User Generated Content (UGC) behind Walmart, Samsung, Best Buy, Proctor &amp;amp; Gamble, etc, etc. Needless to say, we have one of the highest volume third party applications on the internet. Fun stuff. There are other massively successful and smart companies doing similar things (take a look at Disqus or even peek into the Google or Facebook button code).&lt;/p&gt;

&lt;h2&gt;Performance Matters&lt;/h2&gt;

&lt;p&gt;Our core applications were built nearly 7 years ago, and gained features everyday over that period of time. As you can imagine, performance started to suffer. Since we&amp;#8217;re on the product page of major retailers, we knew that this wouldn&amp;#8217;t stand. I was tasked with re-thinking our solution with performance at the forefront of our architectural and deployment strategies. I attacked three different types of performance at varying levels of depth.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network&lt;/li&gt;
&lt;li&gt;Injection/Rendering&lt;/li&gt;
&lt;li&gt;Application&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Bazaarvoice has a developer blog that I sometimes write for, so I wrote an article on &lt;a href="http://developer.bazaarvoice.com/third-party-front-end-performance-part-1"&gt;Third Party Front-end Performance&lt;/a&gt;. Normally I don&amp;#8217;t just link across, but I think this information is actually fairly applicable to a large chunk of developers. So check it out. Feel free to comment either place. Part 2 and 3 to come.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/hTbAum7Q22Y" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2012/04/third-party-front-end-performance-part-1/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[The UX of Language]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/rHaqwsqxKpo/" />
    <updated>2012-03-28T00:13:00-05:00</updated>
    <id>http://alexsexton.com/blog/2012/03/the-ux-of-language</id>
    <content type="html">&lt;p&gt;I once read a tweet &lt;del&gt;that I haven&amp;#8217;t been able to attribute back to its original source&lt;/del&gt; (&lt;a href="http://paulirish.com/"&gt;Paul Irish&lt;/a&gt; has sleuthed and found the original source to be a &lt;a href="https://twitter.com/#!/thegdb/statuses/148293778019581952"&gt;Greg Brockman tweet&lt;/a&gt;), but said something along the lines of&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Web development is the art of finding more complex ways to concatenate strings together.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I think that there&amp;#8217;s a good reason for this.&lt;/p&gt;

&lt;p&gt;As we turn to the next chapter of the web and start building more web &lt;em&gt;applications&lt;/em&gt;, rather than just web &lt;em&gt;documents&lt;/em&gt;, we begin to need to mix language with data. This presents an extremely difficult challenge if you only have to consider a single language. Often times we have to support many.&lt;/p&gt;

&lt;p&gt;While the data density in language increases on our sites and apps, we must consider the user who has to read those sentences. The goal is to offer interesting data to the user without just generating a table and without sounding like Borat writes the copy. You can spend as much time as you&amp;#8217;d like on the interaction and visual design, but if your app doesn&amp;#8217;t have a good flow, you&amp;#8217;re leaving the most important cards on the table: &lt;strong&gt;the content&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;Let&amp;#8217;s Focus on English for a Second&lt;/h2&gt;

&lt;blockquote&gt;&lt;p&gt;Number of Results: 15&lt;/p&gt;

&lt;p&gt;in Number of Categories: 3&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This is the type of language that we&amp;#8217;ve all come to expect out of the web. It gets the point across, but I&amp;#8217;d argue that it&amp;#8217;s not very personal or natural. That may not matter in this particular example, but consider building anything social. Identity is becoming a huge part of the next wave of apps. If you want to have any chance at personalization or identity, then the following isn&amp;#8217;t going to cut it:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Alex added 5 friend(s) to their group on March 19, 2012&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This is in stark contrast to some of the more popular social networks.&lt;/p&gt;

&lt;p&gt;&lt;img src="https://img.skitch.com/20120328-ntk8pcd71jqau26wy5r52k1ri5.jpg" alt="https://img.skitch.com/20120328-ntk8pcd71jqau26wy5r52k1ri5.jpg" /&gt;&lt;/p&gt;

&lt;p&gt;Not only does this correctly address the correct pluralization for &amp;#8216;people&amp;#8217;, it also takes into consideration the offset from the total count of the 3 people that are listed explicitly. This attention to detail doesn&amp;#8217;t stop at decent pluralization, but also gender.&lt;/p&gt;

&lt;p&gt;&lt;img src="https://img.skitch.com/20120328-g74j1tg81w8nn2ryi7uj3wjuf4.jpg" alt="https://img.skitch.com/20120328-g74j1tg81w8nn2ryi7uj3wjuf4.jpg" /&gt;&lt;/p&gt;

&lt;p&gt;Remember the old days when Facebook used to refer to &lt;em&gt;everyone&lt;/em&gt; as a &amp;#8216;their&amp;#8217;? That was weird. Don&amp;#8217;t fall into that trap. When it comes to good user experience, you can&amp;#8217;t ignore the text. If you can go through your app and find any sentence that you&amp;#8217;d write differently if it wasn&amp;#8217;t generated by a computer, you are reducing the effectiveness of that text and degrading the overall experience.&lt;/p&gt;

&lt;h2&gt;Iteration&lt;/h2&gt;

&lt;p&gt;Assuming you&amp;#8217;re sold on the idea of a proper language treatment of your app, let&amp;#8217;s try to solve the problem using some of the examples we&amp;#8217;ve already seen.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;There are X result(s)&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;In JavaScript, the naïve solution would be to do something like the following:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There is one result&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There are &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; results&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This results in a proper english sentence in all cases. That&amp;#8217;s great, but let&amp;#8217;s get a touch more complex. &lt;strong&gt;Now we want to support another language.&lt;/strong&gt; The pluralization rules for English are different than the rules for French. If we want to support French, our solution starts looking more like this:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;en&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There is one result&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There are &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; results&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Le, there are &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; results&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Le, there is &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; result&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This quickly becomes an unscalable solution. You might be thinking &amp;#8220;Well, Alex, I never plan on internationalizing my app, so the rest of this article doesn&amp;#8217;t apply to me.&amp;#8221; - I&amp;#8217;d encourage you to consider the original example as a more pleasant English-only sentence:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;There are 8 results in 2 categories.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Even when ignoring locale, we still have some combinatoric debts to pay. Let&amp;#8217;s check out the code for handling this naïvely:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;ResCount&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;CatCount&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There are &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ResCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; results in &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;CatCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; categories.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;ResCount&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;CatCount&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There is one result in &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;CatCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; categories.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;ResCount&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;CatCount&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There are &amp;quot;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;ResCount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot; results in one category.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;ResCount&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;CatCount&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There is one result in one category.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This is pretty painstaking even without the chore of translating it into other languages. You cannot split up the halves of the sentences safely (especially if you want multiple languages), because the two halves may not match. You can imagine that when gender is added to this sentence, things explode even further.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Alex searched for an image. He found 5 results in one category.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Now we have to multiply that logic times the number of gender choices. Most specs have 3 gender choices: &amp;#8220;male&amp;#8221;, &amp;#8220;female&amp;#8221;, and &amp;#8220;other&amp;#8221;. &amp;#8220;Other&amp;#8221; specifically is treated &amp;#8220;as if you cannot determine the gender of someone who is far away from you.&amp;#8221; In the case of this simple sentence, we&amp;#8217;d need twelve copies of the sentence - one for each combination of gender and plural form of the nouns.&lt;/p&gt;

&lt;h2&gt;Gettext (jed)&lt;/h2&gt;

&lt;p&gt;I recently released a library, &lt;a href="http://slexaxton.github.com/Jed/"&gt;Jed&lt;/a&gt;, for using Gettext style messages in JavaScript. Gettext is a GNU spec that&amp;#8217;s been around for ages. I had been exposed to a little bit of Gettext from my python days, and considered it to be the most popular solution to many of these problems. The main feature of Gettext is that you can decouple the messages from the plural-forms of a given language.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;pluralForms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="s2"&gt;&amp;quot;en&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="s2"&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;We now get back an index of sorts. &amp;#8220;Gettext&amp;#8221; refers to the lookup/loading/encoding mechanism more than anything, but with these plural forms we could do a lookup for the correct string, stored as data.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="s2"&gt;&amp;quot;en&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="s2"&gt;&amp;quot;somekey&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There is one result.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;There are %s results.&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="s2"&gt;&amp;quot;fr&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="s2"&gt;&amp;quot;somekey&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Le, there is %s result.&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Le, there are %s results.&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;en&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;translations&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="p"&gt;][&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;somekey&amp;quot;&lt;/span&gt; &lt;span class="p"&gt;][&lt;/span&gt; &lt;span class="nx"&gt;pluralForms&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt; &lt;span class="p"&gt;](&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;X&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;In this case we&amp;#8217;re using &lt;code&gt;sprintf&lt;/code&gt; style replacement after we do the key lookup. That tends to be the most common way to do substitution with Gettext. Now we have a solution that relies on data instead of one-off code blocks for each message. Also, if your sprintf supports positional variables, you can now solve the problem that different languages order sentences differently than english does.&lt;/p&gt;

&lt;p&gt;Soon after I released Jed it was shared on es-discuss. Immediately &lt;a href="http://norbertlindenberg.com/"&gt;Norbert Lindenberg&lt;/a&gt; stepped up to tell me that I was making a mistake by choosing Gettext. How right he was. The best example of my oversight is actually one that we&amp;#8217;ve already seen:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;There are 8 results in 2 categories&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;How would we represent this in Gettext&amp;#8217;s PO format? The plural-form functions can only take a single number to decide the plural form. This sentence would need to be split up again, which won&amp;#8217;t work across languages and often won&amp;#8217;t work well even in English. Gender can be added in by utlizing Gettext&amp;#8217;s &lt;em&gt;context&lt;/em&gt; feature, but it only goes one level deep. What if I needed an actual context AND a gender selection?&lt;/p&gt;

&lt;p&gt;Norbert was kind enough to point me in the direction of the ICU MessageFormat spec. I could quickly see that some smart people had thought about this a lot longer than I had. Using Jed for Gettext can still be nice if you already have invested in using Gettext in other parts of your stack, but I&amp;#8217;d generally suggest against it in favor of MessageFormat.&lt;/p&gt;

&lt;h2&gt;ICU MessageFormat&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;MessageFormat&lt;/code&gt; is actually just a few specs pasted together, but they look similar. They may seem vaguely familiar to those who have ever used Java&amp;#8217;s &lt;code&gt;ChoiceFormat&lt;/code&gt; utility. They are different in a few ways, but the important part is that they more or less solve multiple plurals and gender specificity without as much of the combinatorics game.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;MessageFormat&lt;/code&gt; spec contains &lt;code&gt;PluralFormat&lt;/code&gt; and &lt;code&gt;SelectFormat&lt;/code&gt; in the most common cases. Using the syntax in &lt;code&gt;PluralFormat&lt;/code&gt; we can address multiple plurals in the same sentence. All the pluralization data is standardized and pulled from &lt;a href="http://cldr.unicode.org/"&gt;CLDR&lt;/a&gt; and not needed as user input. There are &lt;em&gt;keywords&lt;/em&gt; that come back as a result for any given input number: &amp;#8220;zero&amp;#8221;, &amp;#8220;one&amp;#8221;, &amp;#8220;two&amp;#8221;, &amp;#8220;few&amp;#8221;, &amp;#8220;many&amp;#8221;, &amp;#8220;other&amp;#8221;. All languages can be roughly mapped to these keywords, and it is the basis for some of the keywords in the message.&lt;/p&gt;

&lt;p&gt;I won&amp;#8217;t go in to much detail about the syntax, as that&amp;#8217;s not the point of this post.&lt;/p&gt;

&lt;h3&gt;PluralFormat&lt;/h3&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;There&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ResCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;plural&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;are&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;CatCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;plural&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;}.&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Using &lt;code&gt;PluralFormat&lt;/code&gt; we were able to decouple the pluralization of each of the nouns.&lt;/p&gt;

&lt;h3&gt;SelectFormat&lt;/h3&gt;

&lt;p&gt;Gender is usually handled via &lt;code&gt;SelectFormat&lt;/code&gt; which works much like a &lt;code&gt;switch&lt;/code&gt; statement (except &lt;code&gt;default&lt;/code&gt; becomes &lt;code&gt;other&lt;/code&gt;).&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;GENDER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;select&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;male&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;He&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;female&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;She&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;They&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;just&lt;/span&gt; &lt;span class="nx"&gt;found&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;ResCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;plural&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;results&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;CatCount&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;plural&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;one&lt;/span&gt; &lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;other&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;}.&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;At the top we are able to determine the gender to use and then reuse most of our code from above to have a multiple plural and gender-specific sentence in as few characters as possible. Exceedingly complex sentences can often still require nesting and combinatorics, but for the majority of cases, you can avoid repeating any logic.&lt;/p&gt;

&lt;p&gt;There are also complex &amp;#8216;plugins&amp;#8217; that can be used. The &lt;code&gt;offset&lt;/code&gt; option will help you generate sentences like in the google plus example earlier.&lt;/p&gt;

&lt;h3&gt;NumberFormat&lt;/h3&gt;

&lt;p&gt;Technically, I don&amp;#8217;t think &lt;code&gt;NumberFormat&lt;/code&gt; is part of &lt;code&gt;MessageFormat&lt;/code&gt; - but it is usually necessary to pull in. &lt;code&gt;NumberFormat&lt;/code&gt; allows you to internationalize things that we haven&amp;#8217;t even covered yet. Ever consider that other countries use &lt;code&gt;,&lt;/code&gt; characters where the US uses &lt;code&gt;.&lt;/code&gt; and visa versa? Number format is how you handle numbers, percentages, and currencies across languages.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="mf"&gt;1234.5&lt;/span&gt;       &lt;span class="c1"&gt;//Decimal number&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;$1234&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;     &lt;span class="c1"&gt;//U.S. currency&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="mf"&gt;1.234&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;57&lt;/span&gt;&lt;span class="err"&gt;€&lt;/span&gt;    &lt;span class="c1"&gt;//German currency&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="mi"&gt;123457&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;      &lt;span class="c1"&gt;//Percent&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h2&gt;Tools&lt;/h2&gt;

&lt;h3&gt;&lt;a href="https://github.com/SlexAxton/messageformat.js"&gt;messageformat.js&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Shortly after releasing Jed, I released &lt;a href="https://github.com/SlexAxton/messageformat.js"&gt;messageformat.js&lt;/a&gt;. It&amp;#8217;s a much less sexy name, but perhaps I&amp;#8217;ll fix that soon. Google also has an implementation for people using the Google Closure library: &lt;a href="http://code.google.com/p/closure-library/source/browse/trunk/closure/goog/i18n/messageformat.js"&gt;http://code.google.com/p/closure-library/source/browse/trunk/closure/goog/i18n/messageformat.js&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While both are likely to be sufficiently fast, I did implement &lt;code&gt;messageformat.js&lt;/code&gt; as a compile to JS language. This means that at build time, you can &amp;#8216;precompile&amp;#8217; your messages and ditch the majority of the library. This creates some great opportunities to be able to include &lt;code&gt;MessageFormat&lt;/code&gt; style strings directly inside of your precompilable templates and have it all compile to a series of string concats. The readme on the project page should be quite helpful to learn the syntax as well as the integration and api.&lt;/p&gt;

&lt;h3&gt;&lt;a href="https://github.com/owiber/numberformat.js"&gt;numberformat.js&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;My co-worker &lt;a href="https://twitter.com/#!/owiber"&gt;Oliver Wong&lt;/a&gt; was able to do a quick port of the Google Closure &lt;code&gt;NumberFormat.js&lt;/code&gt; to not need Google Closure (under Apache 2).&lt;/p&gt;

&lt;h3&gt;EDIT: &lt;a href="http://momentjs.com/"&gt;moment.js&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;If anyone was wondering how I handle dates in my JS apps, I figured I&amp;#8217;d add it here. Moment.js, by &lt;a href="https://github.com/timrwood"&gt;Tim Wood&lt;/a&gt; is a library that I lean on a lot. There are plenty of additional internationalization libraries that I could start adding (for collation and rtl, etc), but for right now, the built in localization, and friendly &lt;code&gt;ago&lt;/code&gt; syntax of moment.js make for a great user experience around dates.&lt;/p&gt;

&lt;h3&gt;All Together Now&lt;/h3&gt;

&lt;p&gt;I plan on updating Jed to actually contain this group of tools rather than the Gettext ones. I think these tools better suit the needs of modern applications. I will certainly keep the old Jed (Gettext) code around for those that require that format. It&amp;#8217;s not terribly difficult to integrate with these tools separately now, though.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Language is important. It can get complex. A lot of incredibly bright people have been looking into the constraints of same-language message generation, as well as multi-langual message generation (the spec writers, not necessarily the library creators). These tools and/or ideas should be the starting point of any application that desires to have a good UX.&lt;/p&gt;

&lt;p&gt;It doesn&amp;#8217;t matter how many drop-shadows or rounded-corners you have, the user shouldn&amp;#8217;t have to decode your words. The words are often the most valuable experience.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/rHaqwsqxKpo" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2012/03/the-ux-of-language/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[My Thoughts on AMD]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/IniC7-7qPhY/" />
    <updated>2012-03-22T23:08:00-05:00</updated>
    <id>http://alexsexton.com/blog/2012/03/my-thoughts-on-amd</id>
    <content type="html">&lt;p&gt;So I know it was cool to write blog posts about AMD &lt;a href="http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition"&gt;(A CommonJS JavaScript Module Specification)&lt;/a&gt; like a month ago, but I&amp;#8217;ve recently had the desire to put my two cents into the discussion. I am likely not entirely objective - as I frequently use &lt;a href="http://requirejs.org/"&gt;RequireJS&lt;/a&gt; and have even committed &lt;a href="https://github.com/jrburke/requirejs/commits/master?author=SlexAxton"&gt;tiny little parts&lt;/a&gt; to the project that &lt;a href="http://tagneto.blogspot.com/"&gt;James&lt;/a&gt; likely had to rewrite. I would like to point out up front, though, that AMD &lt;code&gt;!==&lt;/code&gt; RequireJS. RequireJS is an implementation of AMD plus a whole ecosystem of usefulness.&lt;/p&gt;

&lt;p&gt;I recently had some in-depth discussions with &lt;a href="http://twitter.com/tomdale"&gt;Tom Dale&lt;/a&gt; who wrote a pretty popular article &lt;a href="http://tomdale.net/2012/01/amd-is-not-the-answer/"&gt;against AMD&lt;/a&gt;. Tom is a good friend and I respect all of his opinions. I wouldn&amp;#8217;t say that he&amp;#8217;s since &amp;#8216;come around&amp;#8217; on the AMD issue, though I may have worn his desire to fight against it. I&amp;#8217;ll take what I can get. His business partner and all-around web-tech badboy &lt;a href="http://twitter.com/wycats"&gt;Yehuda Katz&lt;/a&gt; remains less convinced and sent me a few questions that he wanted answered. I won&amp;#8217;t add them here verbatim, but I&amp;#8217;ll try and touch on a lot of that stuff as well. I think we more or less agree these days (but he by no means necessarily endorses what I&amp;#8217;m writing here). I&amp;#8217;ll explain.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m going to opt to try and not rehash the great responses to Tom&amp;#8217;s concerns by &lt;a href="http://tagneto.blogspot.com/2012/01/reply-to-tom-on-amd.html"&gt;James&lt;/a&gt;, &lt;a href="http://geddesign.com/post/15994566577/amd-is-the-answer"&gt;Dave&lt;/a&gt;, and &lt;a href="http://blog.millermedeiros.com/amd-is-better-for-the-web-than-commonjs-modules/"&gt;Miller&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;AMD is not a script loader&lt;/h2&gt;

&lt;p&gt;This misconception is likely propagated by the fact that RequireJS shows up on all of the script loader shootouts. I have written most of my thoughts on this already in my most popular (read: only) Quora answer: &lt;a href="http://www.quora.com/What-are-the-use-cases-for-RequireJS-vs-Yepnope-vs-LABjs"&gt;What are the use cases for RequireJS vs Yepnope vs LABjs&lt;/a&gt;. I&amp;#8217;ll mostly just leave it at this: &lt;em&gt;Script loading is a means in which AMD/RequireJS meets their requirements. It&amp;#8217;s neither a focus of the project or an integral part to using AMD in production&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;AMD makes async loading possible, not required&lt;/h2&gt;

&lt;p&gt;I often hear that people don&amp;#8217;t have an interest in asynchronous modules. This is perfectly fine. There are tons of integrated systems in full stack web frameworks that do a lot of great things for preprocessing that just don&amp;#8217;t require asynchronous script loading to be great.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AMD is also so &lt;em&gt;other&lt;/em&gt; people can include your module asynchronously.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So if you have your app split up into modules via some preprocessor system, that&amp;#8217;s fine, but if you&amp;#8217;d like your code to be accessible to people who don&amp;#8217;t run the exact same stack as you: AMD works everywhere.&lt;/p&gt;

&lt;p&gt;So write all your code how you like it, and right before you release it on github, consider adding this:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;define&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;function&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;amd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;TheModule&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// Feel free to also leak the global and/or test for a CJS enironment.&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;And to take this a step further, I&amp;#8217;d encourage the preprocessing systems to just process &lt;em&gt;to&lt;/em&gt; AMD.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// Node style modules&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;x&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;y&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Instead of preprocessing this code to work on the web by just concatenating the globals in the correct order, why not just use AMD? It could easily be translated at preprocess time to:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;define&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;x&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;y&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Now you have a module that anyone can pick up (and translate it into their own module format if they&amp;#8217;d like).&lt;/p&gt;

&lt;p&gt;The problem with using anyone else&amp;#8217;s format is that AMD is the only format that is suited well for asynchronous loading. This is not important to one group of people, but it is important to a different group of people, and is a valid concern in web development. In this case, AMD is the inclusive module format.&lt;/p&gt;

&lt;p&gt;As for &amp;#8216;synchronous&amp;#8217; module loading with AMD, the api must use the asynchronous pattern, but if a module is already registered, the result is atomic. Not to mention that it&amp;#8217;s perfectly valid to use the &lt;code&gt;require('x');&lt;/code&gt; syntax when you can be sure a module already exists. The syntax &lt;em&gt;allows&lt;/em&gt; for asynchronous loading, but it doesn&amp;#8217;t require you to load things that way.&lt;/p&gt;

&lt;p&gt;If you don&amp;#8217;t like parts about AMD, and prefer to preprocess, that&amp;#8217;s fine. I would encourage you to process to AMD though. Much like JavaScript is a common compilation target, I&amp;#8217;d like to see AMD become that as well, for modules. It won&amp;#8217;t help when in 5 years every project handles modules with their own preprocessor format.&lt;/p&gt;

&lt;h2&gt;AMD requires preprocessing anyways, right?&lt;/h2&gt;

&lt;p&gt;Yep, but not until build time. Any sane user of RequireJS uses the amazing &lt;a href="https://github.com/jrburke/r.js/"&gt;r.js&lt;/a&gt; build tool before pushing to production. So why not just preprocess on request and output &amp;#8220;modules&amp;#8221; in the correct order and wrap them in a big IIFE?&lt;/p&gt;

&lt;p&gt;It would likely work, but in my opinion there is value in being able to develop directly out of a folder, with only static resources. It&amp;#8217;s the reason that so many new developers are using LESS.js - just load the file and go. It doesn&amp;#8217;t require you to install a watcher, or set up rails, or even learn how to install an additional whole programming language to your highly varied OS landscape. AMD works without all the stuff. It is a developer experience with immediate gratification.&lt;/p&gt;

&lt;p&gt;Many people disagree with the sentiment that our tools should all be able to run on the client side in order to facilitate the idea that our web pages can run out of static directories. I definitely agree that there are tons of uses for preprocessors that run outside of the browser, but I don&amp;#8217;t fundamentally agree that modules are part of the &amp;#8216;just nice to have if you can figure out the watchers&amp;#8217; group of tools. &lt;em&gt;Real&lt;/em&gt; modules are going into browsers soon, and I think they should be part of the first class citizen group of tools that we run in our browsers. Not to mention, if you do opt-in to using a pre-processor and you want someone else&amp;#8217;s preprocessor to be able to understand your modules, you&amp;#8217;ll have to agree on a standard compilation target anyways. What better than AMD?&lt;/p&gt;

&lt;p&gt;Much of what James writes about in his posts are about how there are a few &amp;#8216;meh&amp;#8217; things about AMD, but that it meets nearly every requirement of a module system better than any alternative. He doesn&amp;#8217;t often mention AMD as a compilation target, but I think it solves everyone&amp;#8217;s problems.&lt;/p&gt;

&lt;h2&gt;It&amp;#8217;s not nearly as &amp;#8216;complex&amp;#8217; as you think it is.&lt;/h2&gt;

&lt;p&gt;AMD is implemented by attaching a scriptloader to an object. Load something, store it in the object, if someone else asks for it, pull it back out. Much of the size in RequireJS is for other amazing features and developer tooling. You can switch out RequireJS in production with &lt;a href="https://github.com/jrburke/almond"&gt;Almond&lt;/a&gt; - it is 857 bytes.&lt;/p&gt;

&lt;p&gt;The other notion is that it&amp;#8217;s a chore to write. If we ignore the fact that most modern code editors could easily store the boilerplate for you, I would argue that it&amp;#8217;s actually less characters than &lt;em&gt;not&lt;/em&gt; doing it. Also, (nearly) everyone who says this also complains that it forces them to nest their code an extra level, and then they turn around and immediately wrap all of their code in an IIFE.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// An IIFE for leakage. One level of nesting.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// require statement per dependency&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;path/x&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;path/y&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;path/z&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;path/a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// if you&amp;#39;re doing more commonjs type stuff, not always&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;})(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Here&amp;#8217;s the same AMD module:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="s1"&gt;&amp;#39;path/x&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="s1"&gt;&amp;#39;path/y&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="s1"&gt;&amp;#39;path/z&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="s1"&gt;&amp;#39;path/a&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;doStuff&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;~36% less to type, by my quick and dirty measure (stripping whitespace and counting chars). It can be even less if you don&amp;#8217;t have any dependencies and just include a define at the end of your file like we did in a previous example.&lt;/p&gt;

&lt;p&gt;Sure there&amp;#8217;s a level of nesting, but it&amp;#8217;s one that you&amp;#8217;ll need to put there regardless of whether you&amp;#8217;re using AMD or not. Sure that can be generated at request time, but so can the AMD callback function boilerplate.&lt;/p&gt;

&lt;h2&gt;Why not just polyfill ES6 Modules?&lt;/h2&gt;

&lt;p&gt;Well, first off, they&amp;#8217;re not entirely baked. David Herman - the author of the original Module proposal - just posted a pretty delicious update for some ideas for a &lt;a href="https://mail.mozilla.org/pipermail/es-discuss/2012-March/021543.html"&gt;simpler and sweeter module syntax&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Secondly, I think it&amp;#8217;s a great idea. As soon as the syntax settles back down I think we could all consider setting up preprocessors to allow for the syntax in the browser. This would require a request-time preprocessor because of the invalid nature of the syntax. So if you were able to run a preprocessor, then I think you should use the ES Harmony Module syntax. I think it should then compile to AMD, obviously, but you shouldn&amp;#8217;t ever have to worry about it.&lt;/p&gt;

&lt;h2&gt;Quick RequireJS plug&lt;/h2&gt;

&lt;p&gt;I obviously like AMD a decent amount, but I also think RequireJS is a fantastic tool in my stack. The &amp;#8216;plugin&amp;#8217; architecture is not incredibly well-documented, but it essentially acts as module middleware. My favorite application of this feature involves templates.&lt;/p&gt;

&lt;p&gt;I use the pattern in my &lt;a href="https://github.com/SlexAxton/require-handlebars-plugin"&gt;require-handlebars-plugin&lt;/a&gt; to great effect. Rather than require a precompiled template during dev mode, I simply prefix my module name, and the template compilation occurs before the callback is invoked.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// In a no template middleware world&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;handlebars&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;text!someTemplate.hbs&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;Handlebars&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;strTemplate&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;fnTemplate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Handlebars&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;strTemplate&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;fnTemplate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;some&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This is also similar to the technique where templates are stored in &lt;code&gt;type="script/tmpl"&lt;/code&gt; script tags and pulled in by their id. This means that if you want to compile your templates at build time, you need to fundamentally alter every location that retrieves a template.&lt;/p&gt;

&lt;p&gt;With the hbs template plugin, this is handled for you.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// With require-handlebars-plugin&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;hbs!someTemplate&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;fnTemplate&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;fnTemplate&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;some&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;During development, this loads the template in as text and precompiles it for you. At build time it automatically outputs a precompiled module that is concatenated into the build. This ability alone is like magic to me and I just wanted to tell everyone how much I like it.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;You don&amp;#8217;t have to like AMD more than whatever you use. It would be nice if we had a standard, compatible web module syntax though. I think AMD is the best-suited candidate for that role, and that the preprocessors should use AMD as a compilation target, rather than a direct competitor. Obviously it&amp;#8217;s still cool if you just use it straight up, but that doesn&amp;#8217;t need to happen for it to succeed.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/IniC7-7qPhY" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2012/03/my-thoughts-on-amd/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Uselessware :: A Brief History (JSConf 2011 Talk)]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/jXYFkpt4XPQ/" />
    <updated>2012-03-20T01:15:00-05:00</updated>
    <id>http://alexsexton.com/blog/2012/03/uselessware-a-brief-history-jsconf-2011-talk</id>
    <content type="html">&lt;p&gt;I felt like linking up this talk that I gave on Track B of JSConf in Portland this past year. I feel passionately about the value of writing code that serves no useful purpose other than to bring joy and skills to its implementors and users.&lt;/p&gt;

&lt;p&gt;The talk is pretty short :D&lt;/p&gt;

&lt;iframe src="http://blip.tv/play/g_Mngs64GQI.html" width="596" height="334" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;


&lt;p&gt;&lt;embed type="application/x-shockwave-flash" src="http://a.blip.tv/api.swf#AYLOuBkD" style="display:none"&gt;&lt;/embed&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/jXYFkpt4XPQ" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2012/03/uselessware-a-brief-history-jsconf-2011-talk/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[A New Blogging Engine]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/tUk3pnsjfdk/" />
    <updated>2012-03-19T00:21:00-05:00</updated>
    <id>http://alexsexton.com/blog/2012/03/new-blogging-engine</id>
    <content type="html">&lt;p&gt;All the cool kids are staticly generating these days. I&amp;#8217;m in.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/tUk3pnsjfdk" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2012/03/new-blogging-engine/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Breaking The Cross Domain Barrier (Screencast)]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/VshSET3G7Fg/" />
    <updated>2011-06-06T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2011/06/breaking-the-cross-domain-barrier-screencast</id>
    <content type="html">&lt;p&gt;I decided to try my hand at doing a screencast. I have been told my old cross-domain talk slides have always needed a little more context, so I did that. Hopefully I&amp;#8217;ll get in the habit of doing these, they&amp;#8217;re not so difficult. Enjoy!&lt;/p&gt;




&lt;iframe src="http://player.vimeo.com/video/24705559?title=0&amp;amp;byline=0&amp;amp;portrait=0" width="400" height="300" frameborder="0"&gt;&lt;/iframe&gt;


&lt;p&gt;&lt;a href="http://vimeo.com/24705559"&gt;Breaking The Cross Domain Barrier&lt;/a&gt; from &lt;a href="http://vimeo.com/slexaxton"&gt;SlexAxton&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/VshSET3G7Fg" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2011/06/breaking-the-cross-domain-barrier-screencast/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Breaking The Cross Domain Barrier (or half of it anyways)]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/Tb44L0HpGeI/" />
    <updated>2010-11-30T00:00:00-06:00</updated>
    <id>http://alexsexton.com/blog/2010/11/breaking-the-cross-domain-barrier-or-half-of-it-anyways</id>
    <content type="html">&lt;p&gt;I gave a talk at TXJS and AustinJS about cross domain communication in JavaScript. Here is a video that stopped halfway through that talk.&lt;/p&gt;

&lt;iframe src="http://player.vimeo.com/video/17342024?title=0&amp;amp;byline=0&amp;amp;portrait=0&amp;amp;color=0" width="599" height="329" frameborder="0"&gt;&lt;/iframe&gt;


&lt;p&gt;&lt;a href="http://vimeo.com/17342024"&gt;Breaking The Cross Domain Barrier&lt;/a&gt; from &lt;a href="http://vimeo.com/yayquery"&gt;yayQuery&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;The slides are available here:&lt;/p&gt;

&lt;div id="__ss_4419272"&gt;&lt;strong style="display:block;margin:12px 0 4px"&gt;&lt;a href="http://www.slideshare.net/SlexAxton/breaking-the-cross-domain-barrier" title="Breaking The Cross Domain Barrier"&gt;Breaking The Cross Domain Barrier&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse4419272" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=xdbarrier-100605150515-phpapp02&amp;stripped_title=breaking-the-cross-domain-barrier&amp;userName=SlexAxton" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed name="__sse4419272" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=xdbarrier-100605150515-phpapp02&amp;stripped_title=breaking-the-cross-domain-barrier&amp;userName=SlexAxton" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="padding:5px 0 12px"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/SlexAxton"&gt;Alex Sexton&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;


&lt;p&gt;Sorry for the half-vid, and low quality, but I figured it was worth putting out there, as I&amp;#8217;ve had a few requests for it and I&amp;#8217;m running out of hard drive space. Perhaps with any pressure, I&amp;#8217;d do a screencast.&lt;/p&gt;

&lt;p&gt;Also, this was the day that I took two green nyquil pills thinking that GREEN meant DAY (for dayquill). So I may be a little more relaxed than normal. I&amp;#8217;m sure the beer didn&amp;#8217;t help either. I rather liked it, if I recall.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/Tb44L0HpGeI" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/11/breaking-the-cross-domain-barrier-or-half-of-it-anyways/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[An Accessible Way To Stop Your Content From Flashing (FOUC)]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/Bm7yjsc1GPI/" />
    <updated>2010-09-28T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2010/09/an-accessible-way-to-stop-your-content-from-flashing-fouc</id>
    <content type="html">&lt;p&gt;There are a lot of different reasons why you might see content flash on your page before it&amp;#8217;s done loading. The flash that I&amp;#8217;m talking about usually happens when you are trying to build a JavaScript widget that gracefully degrades when JavaScript is off. You probably feel pretty cool about yourself for writing your JS in an accessible way, but you are sad that it hurts the user experience.&lt;/p&gt;




&lt;p&gt;One of the most common examples of this situation happens with tabbed interfaces, and more specifically the jQuery UI Tab widget. You give it your group of divs and links to turn them into the tabs, but that code doesn&amp;#8217;t run until domready. Before the dom is ready, you&amp;#8217;re original content all shows on the page, then when the tab code runs, it gets hidden.&lt;/p&gt;




&lt;p&gt;Please don&amp;#8217;t set them to hidden in your CSS in order to stop this from happening. This hurts accessibility, SEO, and the laws of white-hat web development, because without JavaScrpt, this content can never be seen. Instead, try this little trick:&lt;/p&gt;




&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;span class='line-number'&gt;24&lt;/span&gt;
&lt;span class='line-number'&gt;25&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;style &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;/*&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;Obviously this is not a real class name, but here you would just&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;set all the elements you want to hide as display:none.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;You should probably make this style whatever the JavaScript ends&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;up setting them to. That way you don&amp;#39;t accidentally add weird styles.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;*/&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nc"&gt;.stuffIDontWantToFlash&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;display&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;noscript&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;style &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/css&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;/*&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;Inside of this noscript block, show the elements, this should behow&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;you want it to look for people without JS - it could even be styled&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;totally different for them if you&amp;#39;d like to lay it out differently without&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;tabs...&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;*/&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nc"&gt;.stuffIDontWantToFlash&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;display&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="k"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/noscript&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;




&lt;p&gt;So there. Now we&amp;#8217;re using the noscript tag to conditionally override our CSS hiding of the elements. You can technically do this with link tags as well, but since you need to put the noscript version in a separate place than the original style (which can be anywhere), it&amp;#8217;s probably not worth the extra http request. Just make sure the noscript override version runs after the initial setting. Cascading at it&amp;#8217;s finest.&lt;/p&gt;




&lt;p&gt;I know what 2 of you are thinking: &amp;#8220;OMG Gross. This does not validate, because a style tag can&amp;#8217;t be anywhere except in the head element&amp;#8221; - well, you could put it in the head element, but that could be weird. In other words, I don&amp;#8217;t really care. It works everywhere.&lt;/p&gt;




&lt;p&gt;
&amp;lt;3z
&lt;/p&gt;




&lt;p&gt;
Alex
&lt;/p&gt;

&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/Bm7yjsc1GPI" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/09/an-accessible-way-to-stop-your-content-from-flashing-fouc/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[What I Learned about the Google Chrome Store]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/F7Q4t_I0Vaw/" />
    <updated>2010-09-18T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2010/09/what-i-learned-about-the-google-chrome-store</id>
    <content type="html">&lt;p&gt;While traveling in Europe this week, I had the pleasure of going to a Google Chrome developer event put on by Mike Mahemoff (The Moff™) and Paul Kinlan (whom Paul Irish says is a genius, so that&amp;#8217;s a good start). I took some notes during the meeting. I didn&amp;#8217;t know tooo much about the chrome app store, so I figured I&amp;#8217;d post what I learned in a very digestible manner for anyone who&amp;#8217;s googling for the right keywords next week.&lt;/p&gt;

&lt;p&gt;A bulleted list of things I learned at the meetup (other than how strong The Moff™ is in real life):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here were some slides for the night: &lt;a href="http://3.ly/y2dd"&gt;http://3.ly/y2dd&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No date on the official release of the store but apparently &amp;#8220;Coming soon&amp;#8221;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There will be a free and a pay model, but the pay model is only launching in the US (then other markets to follow)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There will be a way to do billing monthly/yearly/onetime (paypal (&amp;#8220;harder&amp;#8221;, not sure of the specifics)/googlecheckout)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There will be an API to see if the user really bought something&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;5% of your revenue is theirs, rest is yours (yay) (way better than 30% - wowy)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apps aren&amp;#8217;t chrome specific. They say they&amp;#8217;d love to make stuff work cross browser, but they are going a little bit different direction from W3C widget spec&amp;#8230;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pay to install&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You install apps directly into the browser&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There will be a user-permission popup for (location, notifications, storage, etc)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open now&amp;#8230; I guess this means you can build stuff that works as a chrome app already (but there&amp;#8217;s no store)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8211;Second Half&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;&amp;#8212;-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Apps different than websites (even though theyre both web)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You CAN use flash/silverlight/java if you want, but they don&amp;#8217;t auto install, so if the user doesn&amp;#8217;t have them, you&amp;#8217;re SOL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Google hosted (if you want)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you go Google hosted, they are packaged (let&amp;#8217;s get a spec for this going!), if not, just a URL and a manifest&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I stopped taking notes at this point to actually build a chrome app. It was insanely easy, so I&amp;#8217;m happy about that. Yay chrome apps. I&amp;#8217;d love to see how these pan out. I don&amp;#8217;t think it can work until they are cross-browser, etc, but half the fun of them is that if it&amp;#8217;s a chrome app, it doesn&amp;#8217;t have to work in FF, so you can use specific APIs&amp;#8230; so it&amp;#8217;s a tradeoff.&lt;/p&gt;

&lt;p&gt;Aiight. Tried to keep that as informal as possible. Hope someone wanted this info!&lt;/p&gt;

&lt;p&gt;Alex&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/F7Q4t_I0Vaw" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/09/what-i-learned-about-the-google-chrome-store/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[On "Rolling Your Own" Large jQuery Apps]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/ar4c0CUqMqY/" />
    <updated>2010-08-16T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2010/08/on-rolling-your-own-large-jquery-apps</id>
    <content type="html">&lt;p&gt;As a preface, make sure you&amp;#8217;ve read my super-smart and talented yayQuery co-host Rebecca Murphey&amp;#8217;s blog post on this topic&lt;/p&gt;

&lt;p&gt;here: &lt;a href="http://blog.rebeccamurphey.com/on-jquery-large-applications"&gt;On jQuery Large Applications&lt;/a&gt; and here: &lt;a href="http://blog.rebeccamurphey.com/on-rolling-your-own"&gt;On Rolling Your Own&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Rebecca points out some huge holes in the jQuery-verse when it comes to large-application development, and gives her opinion on why she doesn&amp;#8217;t think jQuery is ever a good fit for a large application. I disagree, and she&amp;#8217;s successfully convinced me to write a post on why I think what I do, so here we are.&lt;/p&gt;

&lt;p&gt;Also, please, no one point out that I prefer Django over Pylons, which is essentially the same argument :D . The difference, though, is that I think Pylons is awesome, and that people should totally be using it for large applications on the backend, as long as they prefer it!&lt;/p&gt;

&lt;p&gt;First, I will start by mentioning that I have written several large applications using jQuery, and that I think that from a &amp;#8216;framework&amp;#8217; perspective, something like Dojo (which Rebecca supports) or YUI3 serves as a much better core to a large application than jQuery. However, arguing that &amp;#8216;you shouldn&amp;#8217;t use jQuery in your large application&amp;#8217; is an entirely different topic. jQuery does not describe or prevent any framework of application development, so you are free to choose your own to suit your needs. I do not advocate the incorrect use of jQuery as the core of your application. I do advocate JavaScript at the core of your application, though.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;jQuery is a tool &lt;/strong&gt;(lolz)&lt;/p&gt;

&lt;p&gt;I build large applications that &lt;em&gt;use &lt;/em&gt;jQuery. I don&amp;#8217;t build large applications &lt;em&gt;on top&lt;/em&gt; of jQuery. This incredibly important distinction hasn&amp;#8217;t been very well clarified thus far in the conversation. I think it&amp;#8217;s a fair ambiguity, however, because while it&amp;#8217;s possible to use jQuery in well-structured ways, it&amp;#8217;s certainly the road less travelled. The &amp;#8216;common jquery user&amp;#8217; tends to throw everything onto the jQuery namespace, and pull in everything as plugins, and generally very tightly couple their applications to jQuery. I think the distinction is still important for the argument, because it doesn&amp;#8217;t rule out the fact that you can write some really nice applications using jQuery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It&amp;#8217;s not jQuery, it&amp;#8217;s you.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think the thought that people are incapable of using jQuery in this manner stems from quite a few bad consulting experiences with companies using jQuery for no reason other than the fact that it&amp;#8217;s &lt;code&gt;the cool thing to do,&lt;/code&gt; but using it entirely in an entirely backwards manner. This is also not a good way of making library decisions (at least in the long term). It doesn&amp;#8217;t reflect poorly on the code in jQuery so much as it reflects poorly on either the messaging from the jQuery team, or just the general population&amp;#8217;s inability to write good code and tendency to do what&amp;#8217;s popular. However, if Dojo were the hip-cool-designer library, they would suffer from &lt;em&gt;the exact same problem&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Any library, in the hands of people who don&amp;#8217;t know what they&amp;#8217;re doing (even FuseJS), will not serve the needs of the application. This is a reality for anything that becomes popular. It&amp;#8217;s easy to like Dojo for the quality of code that comes out of it, but that&amp;#8217;s because the significantly less amount of people who use it are &lt;strong&gt;really good JavaScript Developers&lt;/strong&gt;. That&amp;#8217;s important.&lt;/p&gt;

&lt;p&gt;Being a good JavaScript developer before you start writing your application is the key to building good large applications. &lt;em&gt;It&amp;#8217;s not what library you use. &lt;/em&gt;This is why I write about inheritance in JavaScript for the majority of my large jQuery apps articles. It&amp;#8217;s the JS people need to learn. In fact, I&amp;#8217;d imagine there&amp;#8217;d be some insanely backwards code from people using Dojo who didn&amp;#8217;t know what they were doing. You have to remain level-headed, though, and try to evaluate the tools without bringing in your past experiences with other developers. You can certainly choose Dojo to get away from jQuery noobs, but recommending Dojo to jQuery noobs is just bringing your problem along with you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Roll it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Aiight, with all that out of the way (yikes), let me give my most objective reasoning possible for why I think it&amp;#8217;s ok to use jQuery in a large app. Please keep in mind that I&amp;#8217;m not advocating against Dojo or YUI3, I&amp;#8217;m advocating against the absolute notion that &amp;#8216;jQuery should never be used for large applications.&amp;#8217; Use what you prefer, of course.&lt;/p&gt;

&lt;p&gt;Rebecca&amp;#8217;s core argument against rolling your own jQuery large app is that 1) no one else knows your code-base, so supporting is harder, and 2) the solutions in a library like Dojo are built to work together by smart people who have thought long and hard about the problems, and rolling your own are more fragile and can cause issues with upgrade paths and compatibility, etc. These are valid points, but I think they are painted with a narrow frame of reference for the type of app structure you might use in a large jQuery app.&lt;/p&gt;

&lt;p&gt;It&amp;#8217;s common knowledge that a separation of concerns is key to any large application. Loose-coupling is something that I&amp;#8217;ve blogged extensively about in the past. If you have a problem updating a portion of your application, it&amp;#8217;s because you wrote it too coupled. This is not unique to jQuery. Dojo&amp;#8217;s API stays about as backwards-compatible as they come (seriously), but that doesn&amp;#8217;t mean your old code will just work. In fact one of the few experiences I&amp;#8217;ve had with DojoX code is that some of the less popular DojoX modules often need changes to return the correct values, or not throw errors. The core of the library, has been significantly more impressive in regards to this, but we&amp;#8217;re talking about code that &lt;em&gt;you &lt;/em&gt;write, not the library core.  I am a fan of Dojo&amp;#8217;s backwards compatibility efforts over jQuery&amp;#8217;s. Changing an API in a point release isn&amp;#8217;t always the most friendly change for devs.&lt;/p&gt;

&lt;p&gt;Her list of requirements for a large app is well considered. It is a comprehensive list of things that often come in handy when building a large application. All of these things have been answered by smart people, in the JavaScript community. Much like her example with templating, you can decide which pieces to use (except, directly, not with library specific code&amp;#8230;). Instead of overriding Dojo.templated you just change out the contents of your template rendering function with the new one. If you correctly loosely-coupled your application, then &amp;#8216;yay&amp;#8217;, you switched out a part of your app in less lines of code!&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the list of things that she&amp;#8217;d expect from a framework, along with the appropriate solutions I&amp;#8217;d consider:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;DOM manipulation tools&lt;/strong&gt; - jQuery core&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Ajax tools&lt;/strong&gt; - jQuery core&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;A dependency management and build system&lt;/strong&gt; - RequireJS&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;Clear patterns for code organization, such as namespaced modules&lt;/strong&gt; - The module pattern and a few object literals&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;An inheritance system, preferably one that offers multiple inheritance, for sharing code across modules and staying DRY&lt;/strong&gt; - modules +$.extend&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;A non-DOM-centric, loosely coupled API for communication between modules&lt;/strong&gt; - pub/sub || custom events&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;A widget system that makes use of the inheritance system, with lifecycle management (setup/teardown) and templating&lt;/strong&gt; - $.fn + mustache/microtemplates&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;A system for maintaining templates separate from JavaScript while interning them into the build to eliminate HTTP requests&lt;/strong&gt; - &amp;lt;script &amp;#8220;text/html&amp;#8221;&amp;gt; + text!requirejsdependency&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;A system for abstracting RESTful server communication&lt;/strong&gt; - assumes you &lt;em&gt;want&lt;/em&gt; REST - but $.ajax usually works anyways&amp;#8230;&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;For a UI-intensive project, a rich widget system pluggable to arbitrary data sources and designed with an easily-extended API&lt;/strong&gt; - jQuery UI or ExtJS on jQuery&lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;For an enterprise project, a11y and i18n provisions, as well as clear patterns for file organization &lt;/strong&gt;- jQuery UI has many of these, you can also build them in. Require dictates some directory structure.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;These requests are pretty obviously skewed to someone who likes working in Dojo. They are all pretty awesome ways to do things, but to say that you needed the module pattern is to entirely overlook other very valid ways of structuring complex code. Of course Dojo offers ways to do things like event-oriented programming over object-oriented. The point here is that, if Dojo has answered every question, and jQuery and friends has also answered every question (perhaps not in the same place), it&amp;#8217;s going to be &lt;em&gt;just as hard&lt;/em&gt; to pick up the code base and figure out what&amp;#8217;s going on. I could structure my Dojo app in a way that Rebecca doesn&amp;#8217;t like, and use template overrides for template-languages that she despises, and I could tightly couple my dom elements and their attributes to my data, and it&amp;#8217;d all be in beautiful Dojo. That Dojo has answered all the questions does not facilitate that you understood those answers or that you agree with them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The positives&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I somewhat reject the notion that using jQuery, Underscore, Require, Mustache, and the module pattern (as facilitated by Require) is &amp;#8220;rolling your own.&amp;#8221; Sure you piece them together, by choosing how you use them, but you do the exact same thing when you choose how you use the various parts of Dojo. I think that all of these tools are as strong as the Dojo alternatives. You can argue that you could use any of these tools with Dojo because it&amp;#8217;s so flexible that you can put anything in, but then you can&amp;#8217;t argue that &amp;#8216;rolling your own&amp;#8217; is bad, because that&amp;#8217;s what you just did. Either use Dojo, or agree that sometimes, it&amp;#8217;s not that bad to pull in a different way of thinking, you can&amp;#8217;t have it both ways.&lt;/p&gt;

&lt;p&gt;jQuery normalizes things across browsers when you need it to, and serves as a mostly-fantastic way of doing dom-manip and ajax. If you use it according to it&amp;#8217;s strengths, you still can choose some really strong software alongside it that was specifically designed to be awesome at what it does.&lt;/p&gt;

&lt;p&gt;Underscore gives you a very solid utility library, much like you&amp;#8217;d find in Dojo, and it&amp;#8217;s extensible to boot. You can use it in two of the major paradigms natively, and it falls back to native implementations when it can. It&amp;#8217;s hardly fragile, and it&amp;#8217;s insanely easy to integrate into your project. It&amp;#8217;s no worse or better than Dojo&amp;#8217;s offering.&lt;/p&gt;

&lt;p&gt;RequireJS is likely going to be &lt;em&gt;used &lt;/em&gt;in Dojo 2.0 and James Burke, who wrote Require, also wrote most of the Dojo dependency management system. Require incorporates all the sweet stuff from Dojo, plus some really awesome future stuff coming from the CommonJS peeps. Some apps, though, don&amp;#8217;t require a ton of dependency management. Single page apps are likely not going to be terribly dependency heavy, and if you want&amp;#8230; you can leave out the dependency management system all-together, and still use your modules, just like you always wanted. You can switch it out for LabJS if you want speed too.&lt;/p&gt;

&lt;p&gt;Templating was the example that Rebecca used to show that she could roll her own templating style in Dojo. She used mustache instead of the default Dojo offering. I can&amp;#8217;t argue against that. I&amp;#8217;m in favor of pulling together the correct tools for the job.&lt;/p&gt;

&lt;p&gt;A lot of what is nice about Dojo, is it&amp;#8217;s prescribed format for creating modules. There&amp;#8217;s quite a bit of flexibility, but anyone who could understand the way that Dojo does this could easily understand some of the basic underlying patterns that it&amp;#8217;s enhancing. I can use object.create and the module pattern to my hearts content to structure my app, and that&amp;#8217;s not some &amp;#8216;wild tangent&amp;#8217; that no one will ever be able to unravel. It&amp;#8217;s a simple, and common pattern that you&amp;#8217;d be required to understand to use the Dojo method. Sure there&amp;#8217;s no prescribed way to exactly structure this, but that&amp;#8217;s the case with the &amp;#8216;extremely flexible&amp;#8217; Dojo offering as well.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not advocating creating super complex alternatives to Dojo&amp;#8217;s module structure. I think JavaScript offers a simple and flexible interface to creating and manipulating objects. I can choose which ever way I&amp;#8217;d like. The module pattern is 2 pages of of text and code examples in The Good Parts. Just go read that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dojo is a fantastic library that I would encourage you to pick up and add to your skillset. jQuery can be a fantastic tool to use as well. &amp;#8220;Rolling Your Own&amp;#8221; application with good tools alongside jQuery is no harder to understand than a Dojo app, nor is it harder to support, and it&amp;#8217;s likely more specific to your needs. The fragile part of your code isn&amp;#8217;t in the tools you use, it&amp;#8217;s in the code that you write around them.&lt;/p&gt;

&lt;p&gt;I wish we&amp;#8217;d focus less on whether jQuery or LibX was a good or bad choice for large applications, and focus on the fact that people who don&amp;#8217;t know &lt;strong&gt;JavaScript&lt;/strong&gt; are never going to write well-structured apps. Anyone who does understand the fundamental concepts behind JavaScript would be able to do it well with or without Dojo. Your language should provide your structure, and your toolkits should dictate your tools on top of that structure.&lt;/p&gt;

&lt;p&gt;Learn JavaScript first. Then care about large apps. Then make a smart decision, according to your preferences, on which, if any, library you want to use.&lt;/p&gt;

&lt;p&gt;-Slex&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/ar4c0CUqMqY" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/08/on-rolling-your-own-large-jquery-apps/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[TXJS and ScriptJunkie]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/u7gQ_UC2jLU/" />
    <updated>2010-06-10T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2010/06/txjs-and-scriptjunkie</id>
    <content type="html">&lt;p&gt;I have been pretty neglectful of my blog since I started at Bazaarvoice, but I think I&amp;#8217;m going to try to pick up a little bit. That being said, here&amp;#8217;s a short update.&lt;/p&gt;

&lt;p&gt;I am now a featured author on &lt;a href="http://msdn.microsoft.com/en-us/scriptjunkie"&gt;ScriptJunkie&lt;/a&gt; - a new website from Microsoft about front end development. Check out my post &lt;a href="http://msdn.microsoft.com/en-us/scriptjunkie/ff728622.aspx"&gt;&amp;#8220;Building and Maintaining Large JavaScript Applications&amp;#8221;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll likely cover a few more topics concerning large application structure in the future, both on my blog and on yayQuery and ScriptJunkie.&lt;/p&gt;

&lt;p&gt;Also, TXJS happened. I&amp;#8217;d suggest going to the &lt;a href="http://texasjavascript.com/"&gt;totally awesome webpage&lt;/a&gt; and catching the slides and the speakerrate pages for all the talks to get caught up on how much awesomeness happened. Also, my fridge is still full of left over beer, so if you&amp;#8217;re in town&amp;#8230; beer.js at my place.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/u7gQ_UC2jLU" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/06/txjs-and-scriptjunkie/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Superclassy Inheritance with JavaScript Video]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/x7iJ3nhawzM/" />
    <updated>2010-03-10T00:00:00-06:00</updated>
    <id>http://alexsexton.com/blog/2010/03/superclassy-inheritance-with-javascript-video</id>
    <content type="html">&lt;p&gt;Here is the uncut director&amp;#8217;s edition of my talk given on February 20th, 2010 concerning Inheritance patterns in Javascript. Please forgive the rambling, and the bit of extra footage on either end of the talk.&lt;/p&gt;

&lt;object width="400" height="225"&gt;&lt;param name="allowfullscreen" value="true" /&gt;&lt;param name="allowscriptaccess" value="always" /&gt;&lt;param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=9998565&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00adef&amp;amp;fullscreen=1" /&gt;&lt;embed src="http://vimeo.com/moogaloop.swf?clip_id=9998565&amp;amp;server=vimeo.com&amp;amp;show_title=1&amp;amp;show_byline=1&amp;amp;show_portrait=0&amp;amp;color=00adef&amp;amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"&gt;&lt;/embed&gt;&lt;/object&gt;


&lt;p&gt;&lt;a href="http://vimeo.com/9998565"&gt;Superclassy Inheritance with Javascript - Alex Sexton - NCJS 02/20/10&lt;/a&gt; from &lt;a href="http://vimeo.com/yayquery"&gt;yayQuery&lt;/a&gt; on &lt;a href="http://vimeo.com"&gt;Vimeo&lt;/a&gt;.&lt;/p&gt;


&lt;p&gt;&amp;lt;3z&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/x7iJ3nhawzM" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/03/superclassy-inheritance-with-javascript-video/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Using Inheritance Patterns to Organize Large jQuery Applications]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/We1NBEeTbOk/" />
    <updated>2010-02-25T01:27:00-06:00</updated>
    <id>http://alexsexton.com/blog/2010/02/using-inheritance-patterns-to-organize-large-jquery-applications</id>
    <content type="html">&lt;p&gt;&lt;img style="float: left; margin: 0 10px 10px 0;width:200px;height:150px;" src="http://alexsexton.com/wp-content/uploads/will.jpg" alt="Last will and testament - lolz" /&gt;
I want to introduce/reinforce a pattern for developing large applications with jQuery. I did not invent any of this, but I find that the resources that describe this technique are few and far-between.- so I&amp;#8217;m taking a shot at it.&lt;/p&gt;

&lt;p&gt;By and large, when using jQuery, developers seem to forget the paradigms they learned for well structured code in other languages. This is likely due to the fact that jQuery is effectively neutral when it comes to your structural methodology or inheritance patterns, and therefore doesn&amp;#8217;t push someone in any one direction. Many times in other libraries (See Dojo Declare/Provide/Require, or MooTools Class, etc.), a paradigm is used and exclusively offered, and then code generally ends up more uniform than the oh-so-common-massive-jquery-indented-chains that I&amp;#8217;m sure you&amp;#8217;ve seen .&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not going to necessarily suggest that you use any single inheritance pattern, as there are many options, and each makes sense for different people and different situations. I do however suggest that you know your options. There are a few good reads on the topic of Inheritance in javascript, and I would strongly suggest people read at least a bit of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742"&gt;Javascript: The Good Parts (Chapter 5)&lt;/a&gt; -Douglas Crockford&lt;/li&gt;
&lt;li&gt;&lt;a href="Javascript:%20The%20Good%20Parts%20(Chapter%205"&gt;Prototypal Inheritance in Javascript&lt;/a&gt;) -Douglas Crockford&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.amazon.com/Object-Oriented-JavaScript-high-quality-applications-libraries/dp/1847194141"&gt;Object-Oriented Javascript&lt;/a&gt; -Stoyan Stefanov&lt;/li&gt;
&lt;li&gt;&lt;a href="http://webreflection.blogspot.com/2010/02/javascript-override-patterns.html"&gt;Javascript Override Patterns&lt;/a&gt; -Andrea Giammarchi&lt;/li&gt;
&lt;li&gt;&lt;a href="http://ejohn.org/blog/simple-javascript-inheritance/"&gt;Simple JavaScript Inheritance&lt;/a&gt; -John Resig&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Choosing your form of modularity is an important step. If you come from a background of highly-classical inheritance (I learned Java in school, so&amp;#8230;I know that world) then perhaps starting with a classical implementation is going to be your best choice. If you are trying to stay slim and do the things a little more in the &amp;#8220;JavaScript way&amp;#8221; (a term that means essentially nothing), then you might try to use prototypal inheritance. For my examples, any form of inheritance will at least work on most accounts.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ll jump straight to a code example of this technique in use, and then describe it&amp;#8217;s setup and structure:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;&amp;lt;!-- Just an empty div to begin with --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;mySpeaker&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Then we&amp;#8217;ll run our javascript:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// Call a custom plugin for your object on a dom element&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;#mySpeaker&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;speaker&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;name&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Alex&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// Have quick access to the actual speaker object&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;mySpeaker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;#mySpeaker&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;speaker&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// The interface of the object that you build can&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// wrap more complex dom manipulations that are&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// separated from actual program logic.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;mySpeaker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speak&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;I am a speaker.&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Results in a dom update&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// This shows automatic access to correct element in the dom&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;And the html now looks more like this:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;mySpeaker&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Alex&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;I am a speaker.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;The key here is that we didn&amp;#8217;t have to call something like &lt;strong&gt;$elem.append(&amp;#8216;Alex&amp;#8217;)&lt;/strong&gt; nor did we even have to consider what would happen when a &lt;strong&gt;speaker&lt;/strong&gt; object was called with the &lt;strong&gt;speak()&lt;/strong&gt; function. I consider this to be the key to modular development. This level of abstraction helps keep the &lt;strong&gt;how&lt;/strong&gt; and the &lt;strong&gt;what&lt;/strong&gt; separated (or &amp;#8220;loosely coupled&amp;#8221; - if you like buzzwords). The other thing that was important to note is that after we instantiate the plugin, we have a clear two-way path between our Object and our Dom Element - both have an easy way to immediately access the other. This is important, because we often have different points of entry to jump-start a routine, so being able to access the part that you need quickly and easily is important.&lt;/p&gt;

&lt;p&gt;Implementing this technique is pretty simple, and should actually take less brain power to set up than traversing through the dom in your head to figure out a crazy chain.&lt;/p&gt;

&lt;p&gt;Let&amp;#8217;s start with the &lt;strong&gt;Speaker&lt;/strong&gt; object.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;span class='line-number'&gt;24&lt;/span&gt;
&lt;span class='line-number'&gt;25&lt;/span&gt;
&lt;span class='line-number'&gt;26&lt;/span&gt;
&lt;span class='line-number'&gt;27&lt;/span&gt;
&lt;span class='line-number'&gt;28&lt;/span&gt;
&lt;span class='line-number'&gt;29&lt;/span&gt;
&lt;span class='line-number'&gt;30&lt;/span&gt;
&lt;span class='line-number'&gt;31&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="cm"&gt;/**&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="cm"&gt; * Object Speaker&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="cm"&gt; * An object representing a person who speaks.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="cm"&gt; */&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Speaker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// Mix in the passed in options with the default options&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;({},&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// Save the element reference, both as a jQuery&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// reference and a normal reference&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$elem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// Build the dom initial structure&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// return this so we can chain/use the bridge with less code.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;No name&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;_build&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;h1&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;/h1&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;speak&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// You have direct access to the associated and cached jQuery element&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;p&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;/p&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;I use an object literal here which puts me in the Prototypal Inheritance camp, I believe, but this is just an easily digestible pattern.&lt;/p&gt;

&lt;p&gt;As you can see, there are easy-to-read, small functions, that have a clear purpose. In our use of this pattern, we call api type methods like &lt;strong&gt;speak()&lt;/strong&gt; but not necessarily an internal method (like &lt;strong&gt;_build&lt;/strong&gt;). You can hide your internal functions either by naming convention (not really hiding them), or by using something like the module pattern. In our simple example, I have just added an underscore to the beginning of the function to indicate that it&amp;#8217;s private.&lt;/p&gt;

&lt;p&gt;Code that is organized like this is much easier to test and to change/read. This also allows you to change the way things function without changing the way that the Object api is used. For instance, we could change the &lt;strong&gt;speak&lt;/strong&gt; method to alert the string instead of append it to the related element. We would have to change the internals of the &lt;strong&gt;speak&lt;/strong&gt; function, but we could keep our call to it the same.&lt;/p&gt;

&lt;p&gt;The bridge that we build is probably the most interesting part of this pattern. It&amp;#8217;s a different approach than many of the popular plugins take (slightly different than jquery ui), but it has a few really great benefits.&lt;/p&gt;

&lt;p&gt;The most simple way to do this is by hand:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;span class='line-number'&gt;24&lt;/span&gt;
&lt;span class='line-number'&gt;25&lt;/span&gt;
&lt;span class='line-number'&gt;26&lt;/span&gt;
&lt;span class='line-number'&gt;27&lt;/span&gt;
&lt;span class='line-number'&gt;28&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// Make sure Object.create is available in the browser (for our prototypal inheritance)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// Courtesy of Papa Crockford&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// Note this is not entirely equal to native Object.create, but compatible with our use-case&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;function&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;F&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="c1"&gt;// optionally move this outside the declaration and into a closure if you need more speed.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;F&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;o&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;F&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// Start a plugin&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;speaker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// Don&amp;#39;t act on absent elements -via Paul Irish&amp;#39;s advice&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="c1"&gt;// Create a new speaker object via the Prototypal Object.create&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;mySpeaker&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Speaker&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="c1"&gt;// Run the initialization function of the speaker&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;mySpeaker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// `this` refers to the element&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="c1"&gt;// Save the instance of the speaker object in the element&amp;#39;s data store&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;speaker&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mySpeaker&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;})(&lt;/span&gt;&lt;span class="nx"&gt;jQuery&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;And that&amp;#8217;s it!&lt;/p&gt;

&lt;p&gt;Now you have separated the creation of the plugin from the actual code itself. You are using the plugin to attach objects (with any inheritance patten) to dom elements and visa versa, but the plugin itself is just the connection and initialization code. This means that we could generalize this process further. I first saw this from Scott Gonzalez (of the jQuery UI team) and his code later became the &amp;#8216;widget factory&amp;#8217; in jQuery UI. I prefer to not pass strings into my plugins in order to call functions, but it&amp;#8217;s a valid approach as some people would take issue with having to pull out the object each time they started with a dom element.&lt;/p&gt;

&lt;p&gt;Here is some code that might get you started writing/using a &amp;#8216;bridge&amp;#8217; function (bridge is what&amp;#8217;s found now in jQuery UI 1.8) that can help you attach your general code with a given plugin (since writing that same initialization plugin code multiple times would get old and defeat the whole DRY principle that our inheritance model has hopefully provided). This code is mostly courtesy of Scott Gonzalez because I couldn&amp;#8217;t think of a more stripped down elegant approach to this. I changed it to accept Objects instead of Constructor Functions because that works a little better with my example (prototypal inheritance). I also force it to call my &lt;strong&gt;init&lt;/strong&gt; function in order to save myself an extra call. (&lt;a href="http://pastie.org/517177"&gt;This example&lt;/a&gt; shows Scott&amp;#8217;s use of this method along with John Resig&amp;#8217;s Simple-Inheritance implementation - also very cool.)&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;                &lt;span class="c1"&gt;// optionally, you could test if options was a string&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;                &lt;span class="c1"&gt;// and use it to call a method name on the plugin instance.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;          &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;              &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;          &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// With the Speaker object, we could essentially do this:&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;plugin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;speaker&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Speaker&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;// At this point we could do the following&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;#myDiv&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;speaker&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Alex&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;That&amp;#8217;s about all there is to it. I&amp;#8217;d encourage you to pick some pattern for your development that isn&amp;#8217;t just inline chaining of jQuery function calls. This way of breaking up and organizing functionality in your code serves as a quick and easy jumping-off point for testing and modularity. It&amp;#8217;s much easier to test the individual functions of a modular object than it is to write tests for a single-line chain of jQuery calls.&lt;/p&gt;

&lt;p&gt;Also, I do get some feedback along the lines of &amp;#8220;well, my code is not a plugin&amp;#8221; - &amp;#8220;this isn&amp;#8217;t applicable to my code&amp;#8221; - but I usually tend to disagree. The stigma that a jQuery plugin has to be for general consumption is flawed. I encourage you to use the plugin architecture if you are creating functionality based on a dom element selection. For instance, if you are adding an error notification system, it would be very easy to create a notification object that attaches to a div and has the methods required for notification directly attached to it, rather than having a function that merely hides and shows random dom elements.&lt;/p&gt;

&lt;p&gt;I am doing a round up of performance on a lot of this inheritance usage and I should get to writing another entry on that soon, but from my early tests, using reasonable inheritance is generally &lt;strong&gt;not that expensive&lt;/strong&gt;. If you are pushing the limits of CPUs and browser rendering, you might have to make some sacrifices, but for the general case, the instantiation hit of inherited objects is probably well worth your while.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;d love to hear about the way you approach this problem.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/We1NBEeTbOk" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/02/using-inheritance-patterns-to-organize-large-jquery-applications/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Superclassy Inheritance in JavaScript Developer Day Talk Slides]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/WjyIcC3ZuMk/" />
    <updated>2010-01-31T00:00:00-06:00</updated>
    <id>http://alexsexton.com/blog/2010/01/superclassy-inheritance-in-javascript-developer-day-talk-slides</id>
    <content type="html">&lt;p&gt;I thought I would make a quick post for anyone coming here for my slides from Developer-Day here in Austin.&lt;/p&gt;

&lt;div style="text-align:left" id="__ss_3036379"&gt;&lt;a style="display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/SlexAxton/superclassy-inheritance-in-javascript" title="Superclassy Inheritance In Javascript"&gt;Superclassy Inheritance In Javascript&lt;/a&gt;&lt;object style="margin:0px" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=alexsexton-superclassyinheritanceinjavascript-100130160253-phpapp01&amp;stripped_title=superclassy-inheritance-in-javascript" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=alexsexton-superclassyinheritanceinjavascript-100130160253-phpapp01&amp;stripped_title=superclassy-inheritance-in-javascript" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="font-size:11px;height:26px;padding-top:2px;"&gt;View more &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a style="text-decoration:underline;" href="http://www.slideshare.net/SlexAxton"&gt;Alex Sexton&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;


&lt;hr /&gt;

&lt;p&gt;I plan on giving a screencast of sorts a try, and perhaps even breaking up some of the sections into a few blog posts on the subject. Encapsulation, modularity and code reuse is an interesting topic in any language, but especially when it comes to applying those ideas to real life applications and web sites.&lt;/p&gt;

&lt;p&gt;The demo pages can be found at &lt;a href="http://alexsexton.com/inheritance/demo/"&gt;A Totally Realistic Demo Page for applying Inheritance in Javascript&lt;/a&gt; or whatever.&lt;/p&gt;

&lt;p&gt;Thanks to Viget for having me out to speak today, it was a blast.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/WjyIcC3ZuMk" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/01/superclassy-inheritance-in-javascript-developer-day-talk-slides/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Invalid JSON in jQuery 1.4 and beyond]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/xUgHU7hnmBc/" />
    <updated>2010-01-25T00:00:00-06:00</updated>
    <id>http://alexsexton.com/blog/2010/01/invalid-json-in-jquery-1-dot-4-and-beyond</id>
    <content type="html">&lt;p&gt;I&amp;#8217;m pretty happy about jQuery&amp;#8217;s move to only supporting valid JSON, as well as it&amp;#8217;s standardization across browsers to enforce that rule, even if native JSON parsing isn&amp;#8217;t being used. I think it&amp;#8217;s silly for people to expect things to work when they are passing invalid data back and forth. Much like no one would dare write invalid xml documents for data transfer, the same should be applied to the JSON data format. Simply put, if you aren&amp;#8217;t conforming to the JSON Standards as defined on &lt;a href="http://json.org/"&gt;http://json.org/&lt;/a&gt; - then you aren&amp;#8217;t using JSON. You are just passing Javascript source-code back and forth. I wouldn&amp;#8217;t suggest it.&lt;/p&gt;

&lt;p&gt;Now, I understand there are a variety of libraries and services that currently break the standard. I would strongly suggest you write to them and demand that they follow the spec. Nothing should break for their users, so it&amp;#8217;s not much too ask. Until then I wrote this little lovely plugin so you could consume criminal data sources until they get their acts together:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;jQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getInvalidJSON&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;jQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nx"&gt;callback&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;return &amp;#39;&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;))());&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This is just an unsafe eval of Javascript source that is unwisely used as a data exchange format. I don&amp;#8217;t think it belongs in jQuery, but if you are of the unlucky few that are forced to receive invalid JSON don&amp;#8217;t let it stop you from upgrading to 1.4.&lt;/p&gt;

&lt;p&gt;&amp;lt;3z&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/xUgHU7hnmBc" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/01/invalid-json-in-jquery-1-dot-4-and-beyond/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Don't let document ready slow you down.]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/EYE-JKmsAac/" />
    <updated>2010-01-08T00:00:00-06:00</updated>
    <id>http://alexsexton.com/blog/2010/01/dont-let-document-ready-slow-you-down</id>
    <content type="html">&lt;p&gt;I just wanted to quickly post about a common performance hit that I see in pages (including a bit of my old stuff), especially ones that load data on page load.&lt;/p&gt;

&lt;p&gt;A common pattern for application development loads a page template with the application code included and then makes an asynchronous data request to load all the relevant data.&lt;/p&gt;

&lt;p&gt;One example might be something like:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;jquery.js&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="c1"&gt;// make an ajax request once the dom is ready&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;          &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;ajax.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;            &lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;              &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;                &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;.app-container&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;/div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;              &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;            &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;app-container&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  // Perhaps a very large dom - which makes the page load slower
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;The problem with this is that the request for the page content isn&amp;#8217;t made until the dom is ready, but that request doesn&amp;#8217;t require the dom at all.&lt;/p&gt;

&lt;p&gt;Instead of wrapping the $.ajax() call in a dom ready function, try just wrapping your &lt;code&gt;success&lt;/code&gt; callback function in one instead. This will allow the request to fire off as soon as possible, but will ensure the handling of the data doesn&amp;#8217;t happen until your domready event has fired.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;jquery.js&amp;quot;&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="c1"&gt;// make an ajax request right away&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ajax&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;ajax.php&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;          &lt;span class="nx"&gt;success&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;            &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;  &lt;span class="c1"&gt;//&amp;lt;-- Hey Guys check this out!&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;              &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;                &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;.app-container&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;&amp;lt;/div&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;              &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;            &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;          &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;        &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;app-container&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  // Perhaps a very large dom - which makes the page load slower
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This should speed up the load time of your page. From my testing, there doesn&amp;#8217;t seem to be any issues with this, so I believe it&amp;#8217;s safe to use. The function will fire immediately if your domready event has already fired, and it will wait to fire if the dom isn&amp;#8217;t ready yet. You can have as many document ready calls as you want on your page without overwriting old ones, so don&amp;#8217;t worry about only defining it in one place. I would also imagine that you wouldn&amp;#8217;t need too many more than two or three if you structured your code in an intelligent way.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;As a footnote, this is only one of many things you can do outside of dom ready to help speed up the execution of your code. If you are binding events with &amp;#8216;live&amp;#8217; or if you are just defining functions, I&amp;#8217;d suggest that you do it inside of a closure instead of inside of a dom ready function. Then put just the stuff you need to run with the dom into the dom ready function.&lt;/p&gt;

&lt;p&gt;The reason for this is essentially the same as before. You can allocate all the function definitions and variables while the page is building, rather than afterwards. Anything that you can do asynchronously right away is going to generally be better than waiting until the document is ready. There are a few ways to make this a little better organized, but organization isn&amp;#8217;t the topic, so here is a simple example of code you might write with minimal code execution in the dom ready function. The closure that I have surrounding the entire block of code serves to make the variables have a similar scope affect as it would inside of a document ready function, though it&amp;#8217;s not absolutely necessary.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;span class='line-number'&gt;24&lt;/span&gt;
&lt;span class='line-number'&gt;25&lt;/span&gt;
&lt;span class='line-number'&gt;26&lt;/span&gt;
&lt;span class='line-number'&gt;27&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// This runs immediately&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;a&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;live&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;OKBYE!&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt; &lt;span class="c1"&gt;// define functions outside of the dom ready&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;div.something&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="k"&gt;do&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// you can even use functions that require the&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// dom inside of a defined function as long&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// as you don&amp;#39;t call it until the dom is ready&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;div.somethingelse&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;I don&amp;#39;t need no dom ready&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;     &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;// dom ready&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// Do stuff that requires the dom, and&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// use your functions from outside&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;a.special&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;      &lt;span class="nx"&gt;doSomething&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;special&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;// yay!&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;})(&lt;/span&gt;&lt;span class="nx"&gt;jQuery&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;It&amp;#8217;s nothing revolutionary, but I figured I&amp;#8217;d get it out there!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/EYE-JKmsAac" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2010/01/dont-let-document-ready-slow-you-down/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[yayQuery Podcast 1.0]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/oSmSt_bfOi0/" />
    <updated>2009-11-06T00:00:00-06:00</updated>
    <id>http://alexsexton.com/blog/2009/11/yayquery-podcast-1-dot-0</id>
    <content type="html">&lt;p&gt;A few of the ladies and fellas from the #jquery IRC (&lt;a href="http://ajpiano.com/"&gt;Adam J. Sontag&lt;/a&gt;, &lt;a href="http://paulirish.com/"&gt;Paul Irish&lt;/a&gt;, &amp;amp; &lt;a href="http://rmurphey.com/"&gt;Rebecca Murphey&lt;/a&gt;) and I decided to make a podcast on the topic of jQuery. We landed on the name yayQuery!&lt;/p&gt;

&lt;p&gt;From Paul&amp;#8217;s blog post:&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;We talk about&amp;#8230;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://documentcloud.github.com/underscore/"&gt;Underscore.js&lt;/a&gt; - a great utility belt (very handy for Ruby/Python folks), comes with John Resig&amp;#8217;s microtemplating script and lots more&lt;/li&gt;
&lt;li&gt;Thickbox - &lt;a href="http://jquery.com/demo/thickbox/"&gt;Rest in peace&lt;/a&gt;. Also alternatives: &lt;a href="http://jacklmoore.com/colorbox/"&gt;Colorbox&lt;/a&gt;, &lt;a href="http://jqueryui.com/demos/dialog/"&gt;jQuery UI Dialog&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;jQuery on mobile. &lt;a href="http://phonegap.com/"&gt;Phonegap&lt;/a&gt;, &lt;a href="http://xuijs.com/"&gt;XUI&lt;/a&gt;, &lt;a href="http://www.jqtouch.com/"&gt;jQTouch&lt;/a&gt;, going it alone&lt;/li&gt;
&lt;li&gt;Anti-Pattern of the week: css(key,val)&lt;/li&gt;
&lt;li&gt;$var and Hungarian notation&lt;/li&gt;
&lt;li&gt;&amp;#8230; and dancing&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;If you&amp;#8217;d like a download:
&lt;a href="http://paulirish.com/yayQuery/yayQuery_1.0.mp3"&gt;mp3 audio (30mb)&lt;/a&gt;, &lt;a href="http://paulirish.com/yayQuery/yayQuery_1.0.mp4"&gt;mp4 video (94mb)&lt;/a&gt;, &lt;a href="http://paulirish.com/yayQuery/yayQuery_1.0.ogv"&gt;ogg video (61mb)&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I&amp;#8217;d love to get your feedback on what you liked or didn&amp;#8217;t like. If people seem to enjoy it, we&amp;#8217;d love to step up the production just a bit, but it doesn&amp;#8217;t really make sense quite yet.&lt;/p&gt;

&lt;p&gt;You can also follow us on twitter (&lt;a href="https://twitter.com/yayQuery"&gt;@yayQuery&lt;/a&gt;)  if you want updates for the next episodes and such. Yay!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/oSmSt_bfOi0" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2009/11/yayquery-podcast-1-dot-0/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Goto.js]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/IANmHI1KbmE/" />
    <updated>2009-07-04T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2009/07/goto-dot-js</id>
    <content type="html">&lt;p&gt;Today I launched my new site &lt;a href="http://www.summerofgoto.com"&gt;www.summerofgoto.com&lt;/a&gt;. It is the official new homepage for my new script Goto.js. Goto.js adds the functionality of the goto command into native javascript. It uses James Padolsey&amp;#8217;s parseScripts as a preparser and rewrites the input code to be valid javascript. Leave it to me to write programs solely for the comedic value, but I actually did find some interest in the fact that it is challenging to implement functionality that is so basic to low level programming.&lt;/p&gt;

&lt;p&gt;The script (which can be downloaded at the site) hinges on a single heuristic for implementing Goto. In javascript, while loops can have labels, and they can also have &amp;#8216;continue&amp;#8217; statements that accept a label as the parameter.&lt;/p&gt;

&lt;p&gt;e.g.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class="highlight"&gt;&lt;table&gt;&lt;tr&gt;&lt;td class="gutter"&gt;&lt;pre class="line-numbers"&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='javascript'&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;label1&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;valid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="k"&gt;continue&lt;/span&gt; &lt;span class="nx"&gt;label1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;In effect, this is just a crappy goto statement that is confined to a special case. So my goal in goto.js was to extend this case to all cases. I did this by surrounding everything after a label with a while loop that only runs once by default. The only tricky part being that while loops cannot stretch across multiple functions or blocks. So each while loop ends at the end of its block scope, not the file or script. This is an interesting problem, because typically, when goto was around and actually heavily used, there weren&amp;#8217;t a whole lot of functions being written. Even if I was somehow able to allow you to start running code from the middle of a function from the middle of a different function, I don&amp;#8217;t think it would work, because the context of all the variables that have been passed into the new function cannot be guaranteed to exist.&lt;/p&gt;

&lt;p&gt;The only feature that I am actively toying with currently is a way to allow goto satements to jump to labels that haven&amp;#8217;t been declared yet. After reading a bit on the subject, different languages had different rules about this feature in the past, and some languages therefore also did/do not support forward looking goto statements.&lt;/p&gt;

&lt;p&gt;Enjoy the Summer of Goto!&lt;/p&gt;

&lt;p&gt;P.S. For anyone who is wondering (so far a total of zero people), Summer of Goto is a term that was popularized by Paul Irish, while discussing this script and PHP&amp;#8217;s decision to add goto into their language.&lt;/p&gt;

&lt;p&gt;And for those who do not immediately recognize that this entire thing is a joke, please forgive me. &amp;lt;&amp;#8211;(insurance).&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/IANmHI1KbmE" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2009/07/goto-dot-js/</feedburner:origLink></entry>
  
  <entry>
    <title type="html"><![CDATA[Class Blog:]]></title>
    <link href="http://feedproxy.google.com/~r/AlexSexton/~3/KI88XSl4OrQ/" />
    <updated>2009-06-23T00:00:00-05:00</updated>
    <id>http://alexsexton.com/blog/2009/06/class-blog</id>
    <content type="html">&lt;p&gt;Hello all,&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t expect a terribly large readership, but hopefully I can post some things that will help some people along the way. This will be less of a personal endeavor and more of a location for me to write about some of the things that I create or think are cool in my areas of interest.&lt;/p&gt;

&lt;p&gt;:)&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/AlexSexton/~4/KI88XSl4OrQ" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://alexsexton.com/blog/2009/06/class-blog/</feedburner:origLink></entry>
  
</feed>

