<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Club AJAX – Dallas Ft. Worth Area AJAX Users Group covering: AJAX, JavaScript, HTML, CSS, and Design</title>
	<atom:link href="http://clubajax.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://clubajax.org</link>
	<description>Dallas Ft. Worth Area AJAX Users Group covering: AJAX, JavaScript, HTML, CSS, and Design</description>
	<lastBuildDate>Mon, 07 May 2012 21:43:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>A Dear John Letter to Firefox</title>
		<link>http://clubajax.org/a-dear-john-letter-to-firefox/</link>
		<comments>http://clubajax.org/a-dear-john-letter-to-firefox/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 13:58:47 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[original content]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[H264]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1974</guid>
		<description><![CDATA[Dear Firefox, We met when you were 1.5, and started dating when you were 2.0. We enjoyed making fun of my clueless ex, Internet Explorer. IE seemed great at the time, but you showed me the error of my ways. IE was selfish and wanted to do everything its own way. You truly believed in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://clubajax.org/wp-content/uploads/2012/04/FirefoxLetter.jpg" alt="Dear Firefox Letter" title="FirefoxLetter" width="690" height="173" class="aligncenter size-full wp-image-1975" /><br />
Dear Firefox, </p>
<p>We met when you were 1.5, and started dating when you were 2.0. We enjoyed making fun of my clueless ex, Internet Explorer. IE seemed great at the time, but you showed me the error of my ways. IE was selfish and wanted to do everything its own way. You truly believed in collaboration and gratefully accepted suggestions. When you brought Firebug to the party, I became deeply committed to our relationship. Before Firebug I had no idea how difficult my life was, or the abuse of &#8220;error on line 0 character 0&#8243;; or blank, failed, pages and the silent treatment. You were very up-front with my errors, and kept life spicy with tabs, smart bookmarks, and an Awesome Bar that was truly awesome. Sure you didn&#8217;t load pages as fast as the other browsers, but I&#8217;m not greedy and the most important thing in my life was never&#8230; &#8220;cache&#8221;. Life was never boring, and at the nearest hint that it was, you would whisper in my ear, &#8220;I have a new AddOn&#8230;&#8221; And boy oh boy, I&#8217;ll never forget the first night with that Greasemonkey.<br />
<span id="more-1974"></span><br />
<img src="http://clubajax.org/wp-content/uploads/2012/04/browsers.jpg" alt="browsers" title="browsers" width="150" height="167" class="alignright size-full wp-image-1981" style="margin-left:20px;" />Soon after, other browsers began vying for attention. Safari spawned Webkit, Opera was talking about an HTML5 thing, and Chrome had a hot V8 engine. I honor my commitments, and planned to spend the rest of my career with you. I know the grass is always greener, and it&#8217;s important to love the one you&#8217;re with, and many more cliches, songs and metaphors. </p>
<p>But relationships are a two way street. </p>
<p>At first, I thought the fact that you didn&#8217;t play well with Flash was funny. I mean, you and I are all about HTML5, right? You put Flash in a (sand) box, kneed it in the groin, and we <em>laaaaaa-ughed</em>!</p>
<p>However, I work with video a lot. I understood your attraction to Ogg Vorbis, I really did. But nobody else wanted to play with your hippy friend. Later, I was as excited as you when your rich Uncle Google introduced WebM to everybody. WebM was so charming and intelligent &mdash; all the developers were swooning. But WebM had skeletons in the closet and just didn&#8217;t make good on its promises. Then WebM was stood up by none other than&#8230; Flash. You know you&#8217;ve hit rock bottom when the town drunk stands you up.</p>
<p><img src="http://clubajax.org/wp-content/uploads/2012/04/KittenInMicrowave.jpg" alt="Kitten In Microwave" title="KittenInMicrowave" width="320" height="195" class="alignright size-full wp-image-1978" style="margin-left:20px;" />I&#8217;m glad to see you are opening up to the idea of H264. Your ideals were great, but we can&#8217;t live on a commune eating tofu forever. Don&#8217;t get me wrong, no love is lost on H264, or as I call it, H666, that patent troll who comes to every party claiming someone stole its idea for chip dip. Thanks to you and your rich uncle, H264 was afraid nobody would play, and so agreed to never charge admission. It&#8217;s time to help the web move on and think about other things. H264 may be evil, but it&#8217;s not kittens in the microwave. </p>
<p>Firefox, I can overlook all those things. You&#8217;ve been making it tough, but that&#8217;s okay &mdash; life is tough. But something serious has come up. I noticed you had memory problems since 3.0. I thought it might get better over time, but you&#8217;re 11 now. Your memory is starting to interfere with our relationship.</p>
<p>Which leads to a confession I have to make. A developer has needs. I&#8217;ve been seeing your cousin Chrome on the side.</p>
<p>My wandering eye started with video. Choppy, stuttering, almost unwatchable video. Yes, it was in large part due it playing through that mentally challenged plugin, but you didn&#8217;t leave much option, did you? Oh sure, you use HTML5 to play WebM and Ogg beautifully&#8230; but you know what pages use WebM and Ogg? NONE OF THEM! </p>
<p>Recently at a party when you were chatting with your highfalutin W3C friends about whether video should have a fullscreen API, or whether images should be allowed in canvas cross domain, Chrome cornered me in the bathroom. With trembling fingers, I began opening webpages that had videos. And guess what? </p>
<p>I liked it.</p>
<p>I never meant for it to happen. It was just one of those things. I became witness to a new world where a video would play from beginning to end without a stutter. Even more exciting, I discovered that I could actually smoothly scroll pages again. Don&#8217;t pretend to be shocked Firefox, you know what I&#8217;m talking about! How you give me the cold shoulder and freeze everything while you battle your memory-management Tourette&#8217;s Syndrome as I try and scroll a page that is still loading. Which as mentioned, you take your sweet time to do. </p>
<p>Sorry. I didn&#8217;t mean to get angry. I tried looking the other way. I tried reading email while you were busy being busy. But it&#8217;s gotten so bad that people are starting to blame my code for being slow. I hate to say this, but Firefox, it&#8217;s not me&#8230; it&#8217;s you.</p>
<p>We&#8217;ve had some good times. I never thought of myself as the type who needed a trophy wife, but Firefox, I deserve better. Chrome is hot, available, and every time I look, I see her heaving that ample bosom. </p>
<p>But don&#8217;t worry &mdash; we&#8217;ll continue to see each other since we share 20% custody of users.</p>
<p>By the way, there is someone named MP3 I&#8217;d like you to talk to&#8230;</p>
<p>Sincerely,<br />
Mike</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/a-dear-john-letter-to-firefox/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>HCI Breakthrough: No More Keyboards!</title>
		<link>http://clubajax.org/hci-breakthrough-no-more-keyboards/</link>
		<comments>http://clubajax.org/hci-breakthrough-no-more-keyboards/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 01:34:35 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[humor]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[original content]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1955</guid>
		<description><![CDATA[First we had keyboards, then we had a mouse, then we had a stylus, then we had touchscreens. Now&#8230; none of the above! Built by Rapiscan, thanks to help from from a six billion grant from the federal government, this new, simple device uses a completely unobtrusive set of electronic sensors that detects the slightest [...]]]></description>
			<content:encoded><![CDATA[<p>First we had keyboards, then we had a mouse, then we had a stylus, then we had touchscreens. Now&#8230; none of the above!</p>
<p>Built by <a href="http://www.rapiscansystems.com/">Rapiscan</a>, thanks to help from from a six billion grant from the federal government, this new, simple device uses a completely unobtrusive set of electronic sensors that detects the slightest shift in brain activity and translates it into alphanumeric data.</p>
<p>The futuristic technology is on display in the following image which depicts a high-end developer writing code by only thinking.<br />
<span id="more-1955"></span></p>
<div style="margin:70px 0">
<img src="http://clubajax.org/wp-content/uploads/2012/04/electroshock.jpg" alt="" title="electroshock" width="400" height="300" class="aligncenter size-full wp-image-1957" />
</div>
<p>Of course, this technology is brought to you by the same trusted company that builds the trusted and completely safe Backscatter X-Ray machines that are installed in every neighborhood airport. Continuing with that track record of complete safety, the new keyboard-less input device keeps you completely protected with state of the art grounding straps:</p>
<div style="margin:70px 0">
<img src="http://clubajax.org/wp-content/uploads/2012/04/electroshock-feet.jpg" alt="" title="electroshock-feet" width="500" height="316" class="aligncenter size-full wp-image-1958" />
</div>
<p>The next step for the Rapiscan keyboard-less input? To take your thoughts which may not even be thoughts and translate them into thoughts and then translate that into perfectly legible language.</p>
<div style="margin:70px 0">
<img src="http://clubajax.org/wp-content/uploads/2012/04/babycode.jpg" alt="" title="babycode" width="700" height="429" class="aligncenter size-full wp-image-1965" />
</div>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/hci-breakthrough-no-more-keyboards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5: Undocumented IE6 Mode</title>
		<link>http://clubajax.org/html5-undocumented-ie6-mode/</link>
		<comments>http://clubajax.org/html5-undocumented-ie6-mode/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 00:28:01 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[original content]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1944</guid>
		<description><![CDATA[EDIT: Due to the insistence and flurry of comment activity, links have been added throughout the post for reference. Thank you so much to all my fans! There is an undocumented feature in HTML5: &#8220;IE6 mode&#8221;. After all the pain and suffering all these years, all we had to do was: &#60;script&#62; "IE6 mode" &#60;/script&#62; [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>EDIT: Due to the insistence and flurry of comment activity, links have been added throughout the post for reference. Thank you so much to all my fans!</em></strong></p>
<p>There is an <a href="https://www.google.com/search?q=april+fools">undocumented feature</a> in HTML5: &#8220;IE6 mode&#8221;. After all the <a href="https://www.google.com/search?q=april+fools">pain</a> and <a href="https://www.google.com/search?q=april+fools">suffering</a> all these years, all <a href="https://www.google.com/search?q=april+fools">we</a> had to do was:</p>
<pre><code>
&lt;script&gt;
"IE6 mode"
&lt;/script&gt;
</code></pre>
<p><span id="more-1944"></span><br />
Here is how <a href="https://www.google.com/search?q=april+fools">Club AJAX</a> <a href="http://ie6ify.com/">looks in IE6</a> without the feature:</p>
<div style="text-align:left;">
<img src="http://clubajax.org/wp-content/uploads/2012/04/clubajax-ie6.jpg" alt="" title="clubajax-ie6" width="618" height="377" class="size-full wp-image-1945" />
</div>
<p>And here is <a href="https://www.google.com/search?q=april+fools">how it looks</a> when I add the <a href="https://www.google.com/search?q=april+fools">simple code</a> as shown above:</p>
<div style="text-align:left;">
<img src="http://clubajax.org/wp-content/uploads/2012/04/clubajax-normal.jpg" alt="" title="clubajax-normal" width="535" height="367" class="size-full wp-image-1946" />
</div>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/html5-undocumented-ie6-mode/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Basic Photoshop Etiquette</title>
		<link>http://clubajax.org/basic-photoshop-etiquette/</link>
		<comments>http://clubajax.org/basic-photoshop-etiquette/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 22:20:27 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[Graphical Design]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[original content]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Photoshop]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1919</guid>
		<description><![CDATA[This happens to me constantly, but I only design a small part of my work week. I imagine this happens to full time designers enough to drive them mad. When you send a Photoshop document to another designer, pay some attention to how the layers and groups are named. It&#8217;s really hard managing the file [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://clubajax.org/wp-content/uploads/2012/02/PhotoshopLayers.png" alt="Photoshop Layers" title="Photoshop Layers" width="372" height="751" class="alignleft size-full wp-image-1920" />This happens to me constantly, but I only design a small part of my work week. I imagine this happens to full time designers enough to drive them mad.</p>
<p>When you send a Photoshop document to another designer, pay some attention to how the layers and groups are named. It&#8217;s really hard managing the file of someone else where everything in it is named Layer 2, Layer 2 copy, Layer 2 copy 8, etc., etc. The first thing I generally do is start toggling the visibility of each to figure out which is which and naming things accordingly. But ironically, this has even burned me in the past. The sender actually had the nerve to complain that I wasn&#8217;t able to send the file back with changes because it no longer matched his &#8220;layer structure&#8221;. </p>
<p>And you know, I guess I also disrupted the communication as now we can&#8217;t refer to Layers in the file: <em>&#8220;Look at Layer 13 copy 12. No, no, the <strong>other</strong> Layer 13 copy 12 in group 3 copy 6.&#8221;</em></p>
<p>I&#8217;m just saying, garbage in, garbage out. Show some professional courtesy before you send that PSD.</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/basic-photoshop-etiquette/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>February Meeting &#8211; SMACKDOWN</title>
		<link>http://clubajax.org/february-meeting-smackdown/</link>
		<comments>http://clubajax.org/february-meeting-smackdown/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 17:27:45 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[humor]]></category>
		<category><![CDATA[Meeting]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1912</guid>
		<description><![CDATA[The SMACKDOWN is back! Bob and Mike will go back and forth showing JavaScript tips and tricks, continually escalating and outdoing each other with masterful one-upmanship! The winner gets the eternal mantel of JavaScript guru and the loser &#8211; gets put to DEATH! We will also do ajax news.]]></description>
			<content:encoded><![CDATA[<p>The SMACKDOWN is back! Bob and Mike will go back and forth showing JavaScript tips and tricks, continually escalating and outdoing each other with masterful one-upmanship! The winner gets the eternal mantel of JavaScript guru and the loser &#8211; gets put to DEATH!</p>
<p>We will also do ajax news.</p>
<p><img src="http://clubajax.org/wp-content/uploads/2012/02/Smackdown.jpg" alt="" title="Smackdown" width="600" height="471" class="aligncenter size-full wp-image-1910" /></p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/february-meeting-smackdown/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Context, Call and Bind &#8211; Ninja Level</title>
		<link>http://clubajax.org/javascript-context-call-and-bind-ninja-level/</link>
		<comments>http://clubajax.org/javascript-context-call-and-bind-ninja-level/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 14:59:46 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[original content]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[Object Oriented]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[scope]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1823</guid>
		<description><![CDATA[In my previous article I showed the differences between scope and context, basic problems that arise and how to fix them. If you are just using some JavaScript and maybe jQuery, an understanding of scope is all that is needed to get you by. Once you start using objects or namespaces however, you&#8217;ll start to [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a title="JavaScript Scope and Context – Not the Same Thing!" href="http://clubajax.org/javascript-scope-and-context-not-the-same-thing/">previous article</a> I showed the differences between scope and context, basic problems that arise and how to fix them. If you are just using some JavaScript and maybe jQuery, an understanding of scope is all that is needed to get you by. Once you start using objects or namespaces however, you&#8217;ll start to run into issues with context and will need to use the keyword <code>this</code>. But when you get into object oriented JavaScript, you&#8217;ll need an advanced understanding of context and how to make it work for you. To do this, we&#8217;ll use the <code>call()</code> and <code>apply()</code> methods, and then a backwards compatible version of the new feature Mozilla recently released in JavaScript 1.8.5 called <code><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind">bind()</a></code>.<br />
<img class="aligncenter size-full wp-image-1867" title="JavaScript Function Context Bind" src="http://clubajax.org/wp-content/uploads/2011/12/FunctionContextBind.jpg" alt="JavaScript Function Context Bind" width="730" height="142" /><br />
<span id="more-1823"></span></p>
<h3 title="wtf">Who the Hell Would Ever Use this F@#ing Language Anyway?</h3>
<p>The title of this section is dedicated to a one-time Club AJAX attendee who looked at the next example and was so frustrated at how little he understood it, he started blurting out obscenities. Needless to say, he is now sentenced to life, doing Java.</p>
<p>So, to paraphrase Jack Nicholson&#8230; wait until you get a load of this:</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=AdvancedBrokenContext.js"></script><br />
<figcaption> Example #1 &#8211; Advanced Broken Context<br />
 </figcaption>
</figure>
<p><em>&#8220;Waitaminute!&#8221;</em> I hear you say. <em>&#8220;I applied the context to the function, and <code>onTimeout</code> fired — why didn&#8217;t <code>this.x</code> resolve? And who the hell would ever use this language, anyway?&#8221;</em></p>
<p>I empathize, really. But remember, you don&#8217;t know how to paint without knowing about the color red, and you can&#8217;t really say you know JavaScript unless you know about context and all of its pitfalls. When you are able to understand this concept, it will elevate you from just a guy who writes some JavaScript to outright NINJA!</p>
<p>Before we can decipher why the previous example doesn&#8217;t work, let&#8217;s change it up so we can better break down the issues.</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=AdvancedBrokenContextVariation.js"></script><br />
<figcaption> Example #2 &#8211; Advanced Broken Context Variation<br />
</figcaption>
</figure>
<p>Example #2 basically substitutes <code>otherMethod</code> for <code>setTimeout</code>, so we can side step that particular nuance for now. This example shows a similar situation: we are passing a method to another method and trying to invoke it. However, <code>this.x</code> is still undefined. The reason for this is kind of tricky.</p>
<p>Yes, we used <code>this</code> with <code>onTimeout</code>. But we only used <code>this</code> in order to <em>find</em> <code>onTimeout</code>, we didn&#8217;t use it to <em>invoke</em> <code>onTimeout</code>. If we didn&#8217;t use <code>this</code>, we would get an error saying the function <code>onTimeout</code> is not found, which makes sense, because that would indicate we want a function (as in, <code>var onTimeout();</code>), but what we really want is a method. So we use <code>this</code>, to get the method, and pass it to <code>this.otherMethod</code>.</p>
<div class="example">Refresher: Methods are associated to objects like: <code>object.myMethod = function(){}</code>; while functions are not: <code>var myFunc = function(){}</code>.</div>
<h3 title="theReason">The Reason</h3>
<p>Ironically, if <code>m()</code> or <code>otherMethod()</code> invoked <code>this.onTimeout</code>, it would work. But when we retrieved the method we sort of &#8220;extracted it&#8221; from the object, and passed it as a <em><strong>variable</strong></em>, of a <em><strong>function</strong></em> if you will. It&#8217;s no longer a <em>method</em>, it&#8217;s just a function with no call object bound to it. So we need to re-bind <code>this</code>, which we can do with the <code>call()</code> method:</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=AdvancedBrokenContextVariationFixed.js"></script><br />
<figcaption> Example #3 &#8211; Advanced Broken Context Variation Fixed<br />
 </figcaption>
</figure>
<div class="example">NOTE: The ECMAScript documentation refers to a method&#8217;s bound object as its <em>activation</em> object. David Flanagan, author of <a href="http://www.davidflanagan.com/javascript5/">JavaScript: The Definitive Guide</a> refers to it as a <em>call</em> object, which I like, because you can assign context with a function&#8217;s <code>call</code> method.</div>
<h3 title="isBroken">Is &#8220;this&#8221; Broken?</h3>
<p>We fixed it, but I sense dissatisfaction in you, young Skywalker. <em>&#8220;Why should I jump through these hoops? This language is broken!&#8221;</em> I agree that this aspect is at the least confusing and seems just plain wrong. But there is a reason for this behavior, believe it or not. Remember, JavaScript functions are just data and can be passed around as such.</p>
<p>Okay, if you don&#8217;t believe me, perhaps you&#8217;ll believe Brendan Eich from <em><a href="http://www.aminutewithbrendan.com/pages/20110303">this Talk</a></em>:</p>
<blockquote><p>
[The reason for the keyword "this"] is I wanted functions, which are the main idea in JavaScript, to also be methods; and for them to be methods, they had to have a receiving object who&#8217;s property was the value of that function.
</p></blockquote>
<p>That explanation was a bit&#8230; recursive. Perhaps a simple exercise will help. In Example #4, one object copies a method from another. What should be logged, 10 or 20?</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=CopiedMethod.js"></script><br />
<figcaption> Example #4 &#8211; Copied Method<br />
</figcaption>
</figure>
<p>If you answered 20, you&#8217;d be correct. Even though <code>o.m</code> was copied as data, it was still invoked on the last line with the <code>o2</code> object, which set its context. But you may see what the issue would be if a copied method carried its context around. Then the answer would be 10, derived from the original object. That would make JavaScript look even more broken.</p>
<p>The following is another example of the use of <code>call()</code>. You can borrow a method from one object and apply it to another object temporarily:</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=BorrowedMethod.js"></script><br />
<figcaption> Example #5 &#8211; Borrowing a Method from another Object<br />
 </figcaption>
</figure>
<p>In Example #5, <code>o.changeProps(1);</code> invokes as normal, but the last line, <code>o.changeProps.call(<strong>o2</strong>, 1);</code> calls that same method, yet invokes it within a different object. Admittedly, this example is a bit contrived and is probably making you squirm from all the best practices it violates. But it does show the versatility of the language and exactly how <code>call</code> works.</p>
<div class="example">Note: The first argument of <code>call()</code> should be an activation object and all arguments after that will be passed to the method. <code>apply()</code> works just like <code>call()</code> except the second argument should be an array and is often used to pass the arguments object.</div>
<p>Now that we have a better understanding of context and how to fix it, we can readdress the problem in Example #1. However, we can&#8217;t use <code>call()</code> to fix the context, because that would have to happen within the <code>setTimeout</code> function and we can&#8217;t change native code. Well, we <em>could</em>, but that would be like trying to waterproof a screen with a toothpick. Because the same problem will arise again and again, in callbacks, connections, and myriad other places. We have a better way.</p>
<h3 title="bind">Bind</h3>
<p>The problem can be fixed with the new <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind">bind</a> method in JavaScript.1.8.5. And in spite of the complexity of the problem, the solution is really quite simple:</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=AdvancedBrokenContextFixed.js"></script><br />
<figcaption> Example #6 &#8211; Advanced Broken Context Fixed<br />
</figcaption>
</figure>
<p>Now that <code>this</code> is bound <code>this.setTimeout</code>, we can pass it around and it won&#8217;t lose its context. And that&#8217;s it! Fixed! Good night nurse!</p>
<p>What&#8217;s that? Does this work in <em><strong>what</strong></em> other browser? Hm, I promised some sort of ninja status, didn&#8217;t I? That would necessitate some sort of explanation.</p>
<h3 title="bindUnderHood">Bind Under the Hood</h3>
<p>First of all, no, this does not work in <em>that</em> browser, but we can home brew a utility method that does, which we will add it to the prototype object of the Function constructor. Ever added the <code>forEach</code> method to Arrays? We&#8217;re doing the same thing here except with the Function&#8217;s prototype.</p>
<p>What we need to do is take our existing function and the context passed, and create a newly bound function. We are not going to return the bound function directly because if we did, it would fire immediately, which we don&#8217;t want. We are passing the bound function as data to be invoked later. Therefore we need to return <em>another</em> function that has the bound function inside it.</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=SimpleBindPrototype.js"></script><br />
<figcaption> Example #7 &#8211; Simple Bind Prototype<br />
 </figcaption>
</figure>
<p>You&#8217;ll notice that the function is bound with <code>apply()</code> instead of <code>call()</code>. This is because our utility code has no idea how many arguments may be passed, and <code>apply()</code> handles a variable amount&#8230; of variables.</p>
<p>Include the <em>Simple Bind Prototype</em> early within your code, and Example #6 will work — in all browsers.</p>
<h3 title="nativeBad">But Extending Native Objects is Bad</h3>
<p>Oh, so you&#8217;re one of those purists who believes you shouldn&#8217;t mess with native objects eh? That&#8217;s okay, I&#8217;m concerned about that too. The tide is shifting a bit in the JavaScript library developers community that <a href="http://perfectionkills.com/page/2/">it&#8217;s okay to extend native objects</a> (not host objects) — as long as those extensions are to fix gaps in weaker browsers with standardized functionality. And of course if it&#8217;s your code, you can do whatever you want!</p>
<p>And&#8230; what you want is to <strong>not</strong> extend the native object? That&#8217;s actually a good thing here, because the wrapper-implementation is a little more clear in how it works as there isn&#8217;t the confusion of what &#8220;this&#8221; is, as in Example #7.</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=SimpleBind.js"></script><br />
<figcaption> Example #8 &#8211; Simple Bind<br />
</figcaption>
</figure>
<p>If using the wrapper implementation, you would change the code from <code>setTimeout(this.onTimeout.bind(this), 1);</code><br />
to:<br />
<code>setTimeout(bind(this.onTimeout, this), 1);</code></p>
<p>The bind method passes the argument object, which is quite handy on callbacks. The following example is a recreation of a callback mechanism, which demonstrates how variables are passed:</p>
<figure><script type="text/javascript" src="https://gist.github.com/1396395.js?file=PassVars.js"></script><br />
<figcaption> Example #9 &#8211; Passing Variables<br />
</figcaption>
</figure>
<h3 title="MozillaImplementation">The Mozilla Implementation</h3>
<p>You may have taken a peak at the <a title="Mozilla MDN - Bind" href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind">Mozilla bind page</a>, which would be only natural since I linked to it. I didn&#8217;t recreate their functionality because it&#8217;s a bit complex. Our solution handles 95% of what you would ever do with <code>bind()</code>, while theirs handles new concepts like binding to instance constructors and Arrays. But feel free to experiment!</p>
<h3 title="Conclusion">Conclusion</h3>
<p>Congratulations. If you made it this far into the blog and haven&#8217;t reached for a bottle of aspirin, bottle of alcohol, or a noose, that means you&#8217;ve managed to absorb one of the hardest concepts in JavaScript. Context is the key differentiator between JavaScript and all the other major languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/javascript-context-call-and-bind-ninja-level/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JavaScript Scope and Context &#8211; Not the Same Thing!</title>
		<link>http://clubajax.org/javascript-scope-and-context-not-the-same-thing/</link>
		<comments>http://clubajax.org/javascript-scope-and-context-not-the-same-thing/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 14:35:25 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[original content]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[methods]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[scope]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1808</guid>
		<description><![CDATA[In forums and other places I often see people incorrectly use the term scope when they should be using the term context. Scope applies to the variable and functional access of a function, whereas context is the property and method access of a function. Essentially, scope is function-based, and context is object-based. Scope The following [...]]]></description>
			<content:encoded><![CDATA[<p>In forums and other places I often see people incorrectly use the term scope when they should be using the term context. Scope applies to the variable and functional access of a function, whereas context is the property and method access of a function. Essentially, scope is function-based, and context is object-based.<br />
<img src="http://clubajax.org/wp-content/uploads/2011/11/HyperCube.jpg" alt="JavaScript Scope" title="JavaScript Scope" width="730" height="230" class="aligncenter size-full wp-image-1857" /><br />
<span id="more-1808"></span></p>
<h3 title="scope">Scope</h3>
<p>The following shows a very simple example of the use of scope. <code>funcA</code> has access to <code>var a</code>, and <code>funcB</code> has access to <code>var b</code> and <code>var a</code>:</p>
<figure>
<script src="https://gist.github.com/1396031.js?file=SimpleScope.js"></script></p>
<figcaption>
Example #1 &#8211; Simple Scope<br />
</figcaption>
</figure>
<p>The second log in Example #1 fails because a function captures its scope, and keeps it all to itself. Nobody else has access to <code>funcB</code>&#8216;s scope, not even <code>funcA</code>. However, when <code>funcA</code> captured its scope, it included <code>funcB</code> and therefore <code>funcB</code> has access to all of <code>funcA</code>&#8216;s goodies. </p>
<p>Confused? Try looking at scope as a box made with one-way mirrors. Nothing can see inside the box, but the contents can see out.</p>
<h3 title="Closures">Closures</h3>
<p>A closure is when you then pass funcB to another function somewhere. The scope of <code>funcB</code> is then captured, or, &#8220;enclosed&#8221; and passed along with it. An in-depth look at closures is beyond the &#8220;scope&#8221; (heh heh) of this article, but you can learn more than you ever wanted to know about them from <a href="http://jibbering.com/faq/notes/closures/">Jibbering</a>.</p>
<h3 title="Context">Context</h3>
<p>When learning the JavaScript language, scope gets all of the attention, but the concept that is most difficult to grasp is <em>context</em>. Not knowing what context is and how it works is like trying to learn to paint and not being aware of the color red. The term context can loosely be related to usage of the keyword &#8220;this&#8221;. Hopefully the following example is obvious:</p>
<figure>
<script src="https://gist.github.com/1396031.js?file=SimpleContext.js"></script><br />
<figcaption>
Example #2 &#8211; Simple Context<br />
</figcaption>
</figure>
<p>Both x&#8217;s are able to be accessed because <code>this.x</code> is a property within the <code>m()</code> method&#8217;s context and <code>var x</code> is a variable within its scope. They do not clobber each other.</p>
<p>That was simple enough, but things start to get tricky when functions are used within methods. Take the following modification to the example:</p>
<figure>
<script src="https://gist.github.com/1396031.js?file=BrokenContext.js"></script><br />
<figcaption>
Example #3 &#8211; Broken Context<br />
</figcaption>
</figure>
<div class="example">
Refresher: Methods are associated to objects like: <code>object.myMethod = function(){}</code>; while functions are not: <code>var myFunc = function(){}</code>. Properties are associated to objects like: <code>object.myProperty = 96</code>; while variables are not: <code>var myVariable = 96</code>.
</div>
<p>Example #3 logs <em>1, undefined</em>. What happened is that the <code>f()</code> function was treated as a method. In the previous example, <code>this</code> worked because <code>m()</code> was a method and had the context of <code>o</code>. Note the difference between writing <code>o.m = function()</code> and <code>var f = function()</code>: <code>m()</code> has a receiving object while <code>f()</code> has no such object.</p>
<p>One solution to work around the previous nuance is by accessing <code>x</code> through the global object. Instead of <code>this.x</code>, <code>o.x</code> could be used and that would work. </p>
<p>But if the solution is so simple, then what is the need for the keyword <code>this</code>? The reason is you don&#8217;t always know what object you&#8217;re in, especially with the use of object instances. </p>
<figure>
<script src="https://gist.github.com/1396031.js?file=BrokenContextInstance.js"></script><br />
<figcaption>
Example #4 &#8211; Broken Context Instance<br />
</figcaption>
</figure>
<p>Now <code>this.x</code> is part of an instance object, and there can be several, or even hundreds or thousands of object instances. So it becomes impossible or at least unrealistic to try and access the properties via the object name.  </p>
<p>So perhaps we should just make <code>f()</code> a method, and then it will have access to <code>this.x</code>?</p>
<figure>
<script src="https://gist.github.com/1396031.js?file=ContextBrokenScope.js"></script><br />
<figcaption>
Example #5 &#8211; Context with Broken Scope<br />
</figcaption>
</figure>
<p>Oops. That was definitely not the right thing if you need access to both <code>var x</code> and <code>this.x</code>.</p>
<h3 title="ContextFixScope">Using Context to fix Scope</h3>
<p>So how to fix&#8230; this&#8230; example? One possible solution is to create <code>f()</code> with <code>this</code> context, <em><strong>within</strong></em> the <code>m()</code> method:</p>
<figure>
<script src="https://gist.github.com/1396031.js?file=ContextFixScope.js"></script><br />
<figcaption>
Example #6 &#8211; Context Fixing Scope<br />
</figcaption>
</figure>
<p>Now calling <code>this.f()</code>, works pretty well because now not only does <code>f()</code> has the context of the <code>instance1</code>, but it was created within <code>m()</code>, and so it captures that scope, which includes <code>var x</code>.</p>
<h3 title="ScopeFixContext">Using Scope to Fix Context</h3>
<p>We&#8217;ve probably all run into the following scenario at one time or another. </p>
<figure>
<script src="https://gist.github.com/1396031.js?file=SetTimeoutBrokenContext.js"></script><br />
<figcaption>
Example #7 &#8211; setTimeout with Broken Context<br />
</figcaption>
</figure>
<p>When I first encountered this situation several years ago, I was perplexed for days. It&#8217;s a hard problem to resolve because you don&#8217;t really know what&#8217;s wrong and what keywords to use to search for solutions.</p>
<p>The problem is the context is broken. The way JavaScript currently works is if a function doesn&#8217;t have context, or is not a method associated with an object, it executes in the global space. That should help identify the issue: <code>setTimeout</code> contains an anonymous function that is not associated with <code>this</code>, therefore, <code>this.onTimeout</code> does not resolve correctly.</p>
<p>We can fix this, literally, by assigning it to a variable:</p>
<figure>
<script src="https://gist.github.com/1396031.js?file=ScopeFixContext.js"></script><br />
<figcaption>
Example #8 &#8211; Scope to Fix setTimeout Context<br />
</figcaption>
</figure>
<p><code>this</code> is nothing more than a keyword that is is used to refer to an object. In this case the object is <code>o</code>, and previously it was the <code>C</code> object instance. Since it is just an object, we can assign it to a variable. By convention, the most popular variable name is <code>self</code> since we are referring to our &#8220;self&#8221; in a sense. Now when <code>onTimeout</code> is invoked, it is done so with the proper context and the code works correctly.</p>
<h3 title="conclusion">Conclusion</h3>
<p>Knowing the difference between scope and context will not only help you understand the JavaScript language better, but you&#8217;ll be better able to communicate with other developers and ask the proper questions. Likewise, knowing the difference between methods and functions, and properties and variables is important to communicate exactly what it is you&#8217;re referring to. Remember, <code>var x</code> and <code>this.x</code> are not the same thing!</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/javascript-scope-and-context-not-the-same-thing/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Ask the Client for the Answer</title>
		<link>http://clubajax.org/dont-ask-the-client-for-the-answer/</link>
		<comments>http://clubajax.org/dont-ask-the-client-for-the-answer/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 15:01:40 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[business]]></category>
		<category><![CDATA[Career]]></category>
		<category><![CDATA[original content]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1779</guid>
		<description><![CDATA[When reading the title of this article you may immediately think that it seems obvious. You&#8217;re the commissioned expert, why would you be asking the client how to do your job? That&#8217;s precisely the point; I&#8217;m giving you the answer and not the problem. When given a solution the natural tendency is to take the [...]]]></description>
			<content:encoded><![CDATA[<p>When reading the title of this article you may immediately think that it seems obvious. You&#8217;re the commissioned expert, why would you be asking the client how to do your job?  That&#8217;s precisely the point; I&#8217;m giving you the answer and not the problem. When given a solution the natural tendency is to take the easy way and simply&#8230; implement it. But what is the problem you&#8217;re addressing? And is that the <strong>right</strong> solution? Will it work? How would you even know? So maybe, it&#8217;s not so obvious. In fact I would argue that being provided the solution is much more common than being told the problem.<br />
<img src="http://clubajax.org/wp-content/uploads/2011/11/BailWater.jpg" alt="Bailing Water" title="Bailing Water" width="640" height="327" class="aligncenter size-full wp-image-1803" /><br />
<span id="more-1779"></span></p>
<p>Understanding this dynamic helps build better communication with the client. If the client asks that the button be moved to the left, and you respond it&#8217;s better on the right, you may insult them and their process. Their process may have been: </p>
<ul>
<li>Recommendations from usability studies. </li>
<li>Consulting with expert button location professionals</li>
<li>Several all night meetings among team members who sweated over the button location</li>
</ul>
<p>It&#8217;s likely none of these, and was probably that the client thought about it in his car on the way to work. But either way, the client had a process which incidentally left you out. How do you resolve this? Ask questions.</p>
<p>When presented with only a solution it becomes a riddle. This may put you in the position of having to reverse engineer their decision to get to the problem. <em>Why do you want the button there? Is it because users aren&#8217;t clicking on it? Did a customer complain? Is it because your daughter is left handed?</em></p>
<p>For the most part, moving a button is easy and is probably the best solution to make the client happy. But what if it&#8217;s a complex solution like asking you to increase the buffer time on the video player? If I don&#8217;t ask questions, it may go down like this:</p>
<p style="padding-left:30px;">
I spend a few hours increasing the buffer time from 2 seconds to 5 seconds (this took a long time because it auto-buffered before and there was no code to have a custom setting). The changes are tested and pushed to production. The client now asks for a 10 second buffer. The changes are pushed. The client then says this isn&#8217;t working, now customers are complaining that the video takes to long to load, and the buffer time isn&#8217;t even helping&#8230; on <strong>mobile phones</strong>. You reply, <em>&#8220;Oh, well this code doesn&#8217;t affect mobile phones.&#8221;</em> The customer replies <em>&#8220;Oh, well, I need the videos to load faster on mobile phones.&#8221;</em>
</p>
<p>Getting the problem at the end of the process is obviously unproductive. All those changes were made was a waste of time and money, and it turns out they hurt the product while the real problem wasn&#8217;t addressed &mdash; which in this case may not have something completely different, like a video encoding problem.</p>
<p>Unfortunately we developers are often not the ones interfacing with the client. When a project manager tells me he needs a change, I get real frustrated when he can&#8217;t answer my questions. <em>&#8220;But the client made the request, so I didn&#8217;t question it.&#8221; </em>The truth is: we are not in the business of doing as we are told. We are in the business of making the client successful. Which may at times even be in spite of the client&#8217;s wishes. I&#8217;m not saying to be defiant, because sometimes the client may need to go through a learning process himself. Just make sure you have your change order prepared.</p>
<h3>The Rookie Dilemma</h3>
<p>What do you do if you are so low on the developer food chain that you simply are not allowed in the process and have to just do what you are told? Same thing &mdash; ask questions. If you&#8217;re not asking questions you&#8217;re not learning. But note there is a fine line between asking questions and questioning authority. <em>&#8220;Moving the button to the left destroys the flow of the page &mdash; it looks stupid there!&#8221;</em> is more professionally phrased as <em>&#8220;Okay, although that would upset the flow of the page. Just so I know, why are we moving it?&#8221;</em> If your questions are intelligent enough, you may trigger a new discussion with the client &mdash; and you may even be invited to the party. We&#8217;ve all started low on the totem pole at one or multiple times in our career. Asking good questions is just one way of making the climb.</p>
<h3>Conclusion</h3>
<p>Don&#8217;t give the client what they ask for &mdash; give them what they need. I&#8217;m not going Zen on you. It&#8217;s a simple matter that most of the time they don&#8217;t really know what they need, so they ask for the wrong thing. The most successful man I ever worked for once said &#8220;It&#8217;s easy to make the smart clients look smart. But the real money is in making stupid clients look smart.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/dont-ask-the-client-for-the-answer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Web Applications with MDV</title>
		<link>http://clubajax.org/building-web-applications-with-mdv/</link>
		<comments>http://clubajax.org/building-web-applications-with-mdv/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 13:52:12 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Meeting]]></category>
		<category><![CDATA[original content]]></category>
		<category><![CDATA[Presentation]]></category>
		<category><![CDATA[MDV]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1772</guid>
		<description><![CDATA[MDV or &#8220;model-driven views&#8221;, eschews the concept of widgets in favor of template-based views which are behavior-based and update themselves when the data has changed. Max Motovilov gave a presentation on MDV which was enlightening and thought provoking. He showed how he leveraged The Dojo Toolkit to create behaviors and data stores which update his [...]]]></description>
			<content:encoded><![CDATA[<p>MDV or &#8220;model-driven views&#8221;, eschews the concept of widgets in favor of template-based views which are behavior-based and update themselves when the data has changed.</p>
<p>Max Motovilov gave a presentation on MDV which was enlightening and thought provoking. He showed how he leveraged The Dojo Toolkit to create behaviors and data stores which update his views through his custom-built template system.</p>
<p>Max&#8217;s detailed presentation can be <a href="http://clubajax.org/presentations/mdv-web-applications/">seen here</a>, and you can also see the <a href="https://github.com/MaxMotovilov/adstream-js-frameworks/tree/master/examples/blah">examples he used on GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/building-web-applications-with-mdv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Dart &#8211; Should JavaScript be Replaced?</title>
		<link>http://clubajax.org/google-dart-should-javascript-be-replaced/</link>
		<comments>http://clubajax.org/google-dart-should-javascript-be-replaced/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 13:55:22 +0000</pubDate>
		<dc:creator>Mike Wilcox</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[Dart]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://clubajax.org/?p=1744</guid>
		<description><![CDATA[A memo from a Google employee was leaked earlier this month exposing the new plan for Dart, which they claim to be a new programming language for structured web programming. The memo goes into some detail on what Dart would be, but doesn&#8217;t go into much detail on why Dart should be. In other words, [...]]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://markmail.org/message/uro3jtoitlmq6x7t">memo from a Google employee</a> was leaked earlier this month exposing the new plan for Dart, which they claim to be <a href="http://gotocon.com/aarhus-2011/presentation/Opening%20Keynote:%20Dart,%20a%20new%20programming%20language%20for%20structured%20web%20programming">a new programming language for structured web programming</a>. The memo goes into some detail on what Dart would be, but doesn&#8217;t go into much detail on <strong>why</strong> Dart should be. In other words, it doesn&#8217;t explicitly state the deficiencies in JavaScript. Do they have a point? Should JavaScript be replaced?</p>
<p><img class="aligncenter size-full wp-image-1752" title="ReplaceJS" src="http://clubajax.org/wp-content/uploads/2011/09/ReplaceJS.jpg" alt="Dart to replace JavaScript?" width="730" height="348" /><br />
<span id="more-1744"></span></p>
<h3>Precedence</h3>
<p>You already can run other languages in a browser. There is a <a href="http://www.tcl.tk/man/tcl/tutorial/Tcl0a.html">TCL</a> plugin; IE has VB Script; and there is also C# in the form of Silverlight. And who can forget the most popular plugin and language on the web today&#8230;. <a href="http://download.oracle.com/javafx/">Java FX</a>!?</p>
<p>Flash is the obvious precedent, since at one time in the early 2000&#8242;s it actually did replace JavaScript. However, since then we&#8217;ve had HTML5 with new language APIs, a new and improved browser war with faster engines, and <a href="http://en.wikipedia.org/wiki/ECMAScript#ECMAScript_Harmony">Harmony</a> with buy-in from all the browser vendors.</p>
<p>Flash is also a good example of how you can reach too far. Flash has and has had many impressive features, but a lot of these were later hindered by internet security issues. So we can, for example, wish for a browser language with access to the local file system, but that&#8217;s not going to happen. So what then can we wish for?</p>
<h3>What is not the problem</h3>
<p>One thing I don&#8217;t want to see is strict typing. Okay, maybe a little bit of optionally typed variables, preferably in vectors or typed arrays for speeding up Canvas and 3D. Otherwise, loose typing is what makes JavaScript so versatile. AS3 went to a rigid, Java-like syntax, and it&#8217;s not very fun to code.</p>
<p>As we all know, JavaScript is not the problem nor bottleneck in web page performance. It&#8217;s the DOM, browser compatibility, and server requests. This narrows down the situation to pure language features. HTML5 has added features that make JavaScript more robust than ever. Workers are a simple API (though more difficult in practice) that allow multiple threads for unprecedented scripting power. They also added Storage, so now we don&#8217;t have to suffer at the hands of a 4K cookie. Once Web Sockets security is figured out, giving us faster and more consistent server connections, what more do we need?</p>
<h3>Structure</h3>
<p>I love the lack of structure and wild west nature of developing in JavaScript. But realistically, it&#8217;s very difficult for devs to jump between different libraries like jQuery, MooTools or Dojo. This is a delicate balancing act however, because JavaScript is already a great language and the task is to make it better, not more restrictive. Any structural code changes need to be optional.</p>
<h3>Modules</h3>
<p>It&#8217;s flabbergasting to me that CSS has <code>@import</code> and JavaScript doesn&#8217;t. I think that can only be explain with &#8220;What the Hell?&#8221; Dojo&#8217;s bread and butter is its script loader — solving a problem that shouldn&#8217;t be there in the first place.</p>
<h3>Packages</h3>
<p>The unique thing about a Flash movie SWF is that it is a self contained file that can include all the necessary resources, minimizing or eliminating multiple server requests. JavaScript has no such ability, save some real kludgy experiments. Mozilla is addressing this issue with their <a href="http://people.mozilla.com/~jlebar/respkg/">Resource Packages Proposal</a>.</p>
<h3>Classes</h3>
<p>Yes, JavaScript has prototypes and we have our <a href="http://clubajax.org/simple-and-easy-javascript-inheritance/">syntactic sugar to give us inheritance</a>, but again, it&#8217;s hard to write standardized code. jQuery, MooTools and Dojo all address this limitation is vastly different ways, fracturing web development.</p>
<h3>Fix this!</h3>
<p>It would be nice if &#8216;this&#8217; were optional. Object oriented code is a bit discouraging in JavaScript because you are punished with tens of hundreds of &#8216;this&#8217; keywords peppered throughout your code, which bloats it and doesn&#8217;t help readability. It also hampers newbie developers who have trouble grokking the concept of context invoked functions (like say, calling an object method from a <code>setTimeout</code>). Adobe claims to have fixed &#8216;this&#8217; in ActionScript 3.0&#8230; but not really. ActionScript is essentially Java with JavaScript mashed on top of it. When you write actual ECMAScript in an ActionScript file, you need to use &#8216;this&#8217; or the compiler gets confused.</p>
<p>What I&#8217;m suggesting would require the co-mingling of context and scope. The variable search would start with the initially scoped function, then the object and prototype chain, then the remainder of the scope chain. Would this implementation affect performance? When I write a JavaScript engine I&#8217;ll let you know! Until then, I&#8217;m punting to the browser vendors!</p>
<h3>Protected Variables</h3>
<p>Yes, everyone wants their precious private variables, but <a href="http://clubajax.org/javascript-private-variables-are-evil/">I&#8217;m on record for not being a fan</a>, as I feel they are over used and abused. Protected variables on the other hand, give you the best of both worlds: the public API can be exposed as the clear intent, and the protected variables and methods can only be accessed or changed if the class is extended to explicitly override them. If you want to change my library code you need to work for it, yo!</p>
<h3>Maff</h3>
<p>Yes, I&#8217;m referring to the fact that <code>.1 + .2 = 0.30000000000000004</code>. I understand that it&#8217;s <a href="http://download.oracle.com/docs/cd/E19957-01/806-3568/ncg_goldberg.html">common problem in floating point numbers using binary digits.</a> I also concede that this situation rarely is an issue for me, because I do largely graphical work, not work that requires extreme numerical accuracy like accounting. Regardless, a new Math namespace would be a welcome addition, and even better, it could be a strictly typed namespace that allows only floating point numbers.</p>
<h3>Tooling</h3>
<p>The Google memo says that one major problem with JavaScript is the lack of ability to &#8220;tool it&#8221;. Not being a server side programmer (and when I play one on TV, I use PHP), I&#8217;m not familiar with these tools, or lack thereof. But I&#8217;m guessing they are referring to the loose and dynamic nature of JavaScript not allowing an IDE like Eclipse to track objects and report broken code.  I&#8217;m going to punt a little bit here, and claim: the lack of tools forces you to write better, loosely coupled, encapsulated code. Tools make you lazy! I can hammer in nails with my forehead and drive screws with my teeth! Raaawarr!</p>
<h3>Standards Politics</h3>
<p>At first glance it may seem to be a great benefit to develop a language outside of the <a href="http://www.w3.org/">W3C</a> and their sometimes draconian politics, their self centered policies, and their ability to take a great idea and turn it into a shitty one. Lots of languages are written, but only a few catch on. For every great language like Python, you get several like DOS, LotusScript, Authorware, Lingo, or Cold Fusion — or any other Macromedia derived language. Speaking of Macromedia, the early Flash scripting language was proprietary, cumbersome, and unusable. They switched to an ECMAScript-based syntax, and ActionScript exploded with success.</p>
<p>Believe me, I&#8217;m not championing the standards body that almost killed off HTML. Nor am I saying that designing a language by committee is a good idea. It&#8217;s just that you are fighting an uphill battle if you throw out the standards and start from scratch, even if it&#8217;s a better idea. The <a href="http://en.wikipedia.org/wiki/United_States_customary_units">US System of Measurements</a> is an example of design by a committee of retarded orangutangs flinging their feces at finger paintings to make their discussions — yet the Metric System was not widely adopted. Yet while Python was invented by <a href="http://en.wikipedia.org/wiki/Guido_van_Rossum">one guy</a>, it evolved in an open source community.</p>
<h3>Conclusion</h3>
<p>Can JavaScript be replaced? My guess is at worst never, and at best ten plus years. JavaScript developers are very protective of their domain, sometimes to a fault, and they don&#8217;t appear to be very welcoming of changes; they often are even averse to Harmony proposals.  New technologies require a <a href="http://en.wikipedia.org/wiki/Killer_app">killer app</a> in order to catch on. Flash had <a href="http://youtube.com">YouTube</a>, Silverlight had <a href="http://netflix.com">NetFlix</a>, and Java FX had&#8230; well, I rest my case. Since Dart has corporate giant Google behind it, a killer app is definitely not out of the question. And if so, the big brains at Google could make this happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://clubajax.org/google-dart-should-javascript-be-replaced/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

