<?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>ReadyState4 &#187; JavaScript</title>
	<atom:link href="http://readystate4.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://readystate4.com</link>
	<description>JavaScript, Web Development, Ruby, and Technology.</description>
	<lastBuildDate>Fri, 27 Jan 2012 18:37:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Older is sometimes better or why I use an old version of jQuery.</title>
		<link>http://readystate4.com/2011/07/21/older-is-sometimes-better-or-why-i-use-an-old-version-of-jquery/</link>
		<comments>http://readystate4.com/2011/07/21/older-is-sometimes-better-or-why-i-use-an-old-version-of-jquery/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 10:18:02 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[zepto]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=382</guid>
		<description><![CDATA[For the last year or so I&#8217;ve been predominantly focused on mobile web applications. While I&#8217;m a big fan of jQuery, at it&#8217;s current revision of *32.18 KB (compressed and gzipped) I think it&#8217;s generally too big for the mobile web. That&#8217;s when I discovered Zepto, a jQuery-like library that features 90% of the same [...]]]></description>
			<content:encoded><![CDATA[<p>For the last year or so I&#8217;ve been predominantly focused on mobile web applications. While I&#8217;m a big fan of jQuery, at it&#8217;s current revision of *32.18 KB (compressed and gzipped) I think it&#8217;s generally too big for the mobile web. That&#8217;s when I discovered <a href="http://zeptojs.com/">Zepto</a>, a jQuery-like library that features 90% of the same functionality at a weight of 4.8 KB (compressed and gzipped). Life was good again and I resumed working with iOS and Android web apps, bidding IE adieu.</p>
<p>Fast forward to now and I need to make some general web pages again for a project and I need to support IE once more. These pages have some light-to-moderate js functionality and though I could write a small library from scratch, I&#8217;d be a fool in wasting so much time, though minimally, I only need:</p>
<ul>
<li>Cross-browser event support</li>
<li>Cross-browser ajax support</li>
</ul>
<p>Though one does arguably write faster and more concisely (smaller file size) if one has: </p>
<ul>
<li>A chainable API</li>
<li>A CSS selector engine</li>
</ul>
<p>The answer? Use an older version of jQuery. jQuery 1.2.6 for example is 17.18 KB (compressed and gzipped). Almost half as small as the current version. It gives me all four requirements above. Every version of jQuery has been battle-hardened against the most finicky older browsers and the newest batch of browsers aren&#8217;t really causing too much trouble. I had been writing with Zepto in Chrome initially when I made the switch to test in IE. I made the switch to 1.2.6 without issue. IE and all browsers are happy.</p>
<p>While I would love to take credit for thinking this through, it actually happened by accident. I referenced jQuery version 1.2.6 from Google&#8217;s CDN instead of 1.6.2.</p>
<p>I&#8217;m sure someone&#8217;s going to comment how I&#8217;m missing some major optimizations in later versions, but after trying the project out, I already have split second performance using an old build. If I start doing crazy animations or need .live, I&#8217;ll move up some revisions. If you do plan to try this out for yourself, know that jQuery 1.3 (20.08 KB) is when <a href="http://docs.jquery.com/Release:jQuery_1.3">Sizzle</a> was introduced and in <a href="http://api.jquery.com/category/version/1.6/">jQuery 1.6</a> a lot of the API was modified or had signature changes (nothing that&#8217;s affected me so far).</p>
<p>Here&#8217;s a list of some versions along with their file sizes. Check the <a href="http://blog.jquery.com/">blog</a> for more details.<br />
1.6.2 (32.18 KB) &#8211; misc small bugfixes<br />
1.5 (30.12 KB) &#8211; ajax timeout and abort<br />
1.4.2 (24.86 KB) &#8211; .delegate<br />
1.4 (27.25 KB) &#8211; extended .live support<br />
1.3 (20.08 KB) &#8211; Sizzle and Live<br />
1.2.6 (17.18) &#8211; 100% faster events<br />
1.2 (17.21 KB)</p>
<p>And don&#8217;t forget if you&#8217;re using Google&#8217;s CDN (a good idea), <a href="http://stackoverflow.com/questions/6382639/is-it-safe-to-reference-googles-jquery-library/6382668#6382668">always fallback to your own version, too, just in case</a>.</p>
<p>*2.6.1, I use Charles Debugging Proxy for measurements.</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2011/07/21/older-is-sometimes-better-or-why-i-use-an-old-version-of-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Docco: cool JS documentation generator</title>
		<link>http://readystate4.com/2011/06/27/docco-cool-js-documentation-generator/</link>
		<comments>http://readystate4.com/2011/06/27/docco-cool-js-documentation-generator/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 05:33:30 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=364</guid>
		<description><![CDATA[I noticed both backbone.js and spine.js are using it: http://jashkenas.github.com/docco/ Creates pages like this: http://documentcloud.github.com/backbone/docs/todos.html]]></description>
			<content:encoded><![CDATA[<p>I noticed both <a href="http://documentcloud.github.com/backbone/">backbone.js</a> and <a href="http://maccman.github.com/spine/">spine.js</a> are using it:</p>
<p>http://jashkenas.github.com/docco/</p>
<p>Creates pages like this:</p>
<p>http://documentcloud.github.com/backbone/docs/todos.html</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2011/06/27/docco-cool-js-documentation-generator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript compression: Google Closure Compiler vs UglifyJS</title>
		<link>http://readystate4.com/2011/04/21/javascript-compression-google-closure-compiler-vs-uglifyjs/</link>
		<comments>http://readystate4.com/2011/04/21/javascript-compression-google-closure-compiler-vs-uglifyjs/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 18:13:12 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=306</guid>
		<description><![CDATA[After setting up a make / jsmin build system for concatenating and minifying CSS files I looked around to see what&#8217;s the best compresser to do the same with JS these days and it looks like it&#8217;s a toss-up between Google Closure Compiler and UglifyJS. I&#8217;ve heard from two different developers about problems caused by [...]]]></description>
			<content:encoded><![CDATA[<p>After setting up a make / jsmin build system for concatenating and minifying CSS files I looked around to see what&#8217;s the best compresser to do the same with JS these days and it looks like it&#8217;s a toss-up between <a href="http://code.google.com/closure/compiler/">Google Closure Compiler</a> and <a href="https://github.com/mishoo/UglifyJS">UglifyJS</a>.</p>
<p>I&#8217;ve heard from two different developers about problems caused by Google Closure compiler: one edge-case where it incorrectly rewrote some JS, and the other about having to write your JS a certain way for maximum efficiency. After reading up on UglifyJS <a href="http://badassjs.com/post/971960912/uglifyjs-a-fast-new-javascript-compressor-for-node-js">here</a> and seeing how both jQuery and <a href="https://github.com/madrobby/zepto">Zepto</a> are now using Uglify (jQuery moving from GCC to Uglify <a href="http://bugs.jquery.com/ticket/7973">3 months ago</a>), I think I&#8217;ll give UglifyJS a try and let you know how it goes. The readme file that comes with Ugly is in both html and <a href="http://orgmode.org/">org</a> formats. I&#8217;m liking it already&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2011/04/21/javascript-compression-google-closure-compiler-vs-uglifyjs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Great article for learning JavaScript for existing programmers</title>
		<link>http://readystate4.com/2010/06/04/great-article-for-learning-javascript-for-existing-programmers/</link>
		<comments>http://readystate4.com/2010/06/04/great-article-for-learning-javascript-for-existing-programmers/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 19:36:39 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/?p=67</guid>
		<description><![CDATA[I&#8217;ve been teaching JavaScript to a person with no programming experience and one with lots of programming experience in other languages. Both situations can be tough as one has to learn certain programing concepts (as well as how the web generally works) and the other must unlearn some that don&#8217;t apply here (like getting out [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been teaching JavaScript to a person with no programming experience and one with lots of programming experience in other languages. Both situations can be tough as one has to learn certain programing concepts (as well as how the web generally works) and the other must unlearn some that don&#8217;t apply here (like getting out of the strongly-typed world and appreciating the benefits of duck-typing).</p>
<p>Explaining various concepts in JS such as prototypes, closures, and even &#8220;literal&#8221; shorthand is interesting. I find the questions from both ends  great—sometimes even challenging to explain which actually strengthens me as a JS developer. Still some concepts are hard to explain and the JavaScript Rhino book is too large and boring to dish out as homework. Then I stumbled across this page by Simon Willison which was written as a re-introduction to JavaScript but also makes a perfect condensed overview of what JS is for existing programmers: <a href="https://developer.mozilla.org/en/A_re-introduction_to_JavaScript">https://developer.mozilla.org/en/A_re-introduction_to_JavaScript</a>. It even goes over a little history of the language and how to avoid nasty memory leaks in IE (circular references). Saves us a lot of time and explaining so that we can continue with more complex topics.</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2010/06/04/great-article-for-learning-javascript-for-existing-programmers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Memoization</title>
		<link>http://readystate4.com/2009/02/25/javascript-memoization/</link>
		<comments>http://readystate4.com/2009/02/25/javascript-memoization/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 17:18:30 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/2009/02/25/javascript-memoization/</guid>
		<description><![CDATA[I was taking a look at my friend Takashi&#8217;s JavaScript tweener which isn&#8217;t released yet and noticed he setup his code in a particular way for a few methods that get called dozens of times a second. He explained to me that it was for optimization through memoization. I ran a test case, and indeed [...]]]></description>
			<content:encoded><![CDATA[<p>I was taking a look at my friend Takashi&#8217;s JavaScript tweener which isn&#8217;t released yet and noticed he setup his code in a particular way for a few methods that get called dozens of times a second. He explained to me that it was for optimization through <a href="http://en.wikipedia.org/wiki/Memoization" title="Wikipedia entry">memoization</a>. I ran a test case, and indeed it&#8217;s much faster. Check it out:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">a <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
a.<span style="color: #660066;">deep</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
a.<span style="color: #660066;">deep</span>.<span style="color: #660066;">variable</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    here<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> plain<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">deep</span>.<span style="color: #660066;">variable</span>.<span style="color: #660066;">here</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> memoized<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> z <span style="color: #339933;">=</span> a.<span style="color: #660066;">deep</span>.<span style="color: #660066;">variable</span>.<span style="color: #660066;">here</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        document.<span style="color: #660066;">body</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">createTextNode</span><span style="color: #009900;">&#40;</span>z<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
now <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> max <span style="color: #339933;">=</span> <span style="color: #CC0000;">5000</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> max<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        plain<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> now<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
now <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> max <span style="color: #339933;">=</span> <span style="color: #CC0000;">5000</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> max<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        memoized<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> now<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// plain:  759</span>
<span style="color: #006600; font-style: italic;">// memoized: 36</span></pre></div></div>

<p>There&#8217;s a more complex example on the subject posted a month ago on <a href="http://ajaxian.com/archives/speed-up-your-javascript-with-memoization">Ajaxian</a> and an easier to understand one on Oliver Steele&#8217;s <a href="http://osteele.com/archives/2006/04/javascript-memoization">blog</a> written back in 2006.</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2009/02/25/javascript-memoization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The difference between != and =!</title>
		<link>http://readystate4.com/2008/12/31/the-difference-between-and/</link>
		<comments>http://readystate4.com/2008/12/31/the-difference-between-and/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 17:38:10 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/12/31/the-difference-between-and/</guid>
		<description><![CDATA[I was helping a friend troubleshoot some of her code today and found the culprit to be a typo in one of her conditional statements: // var USERID = 12345; if &#40;USERID =! null&#41;&#123; // code &#125; Her expression was always resolving to true because she had inverted her != (&#8220;not-null&#8221;) check which was actually [...]]]></description>
			<content:encoded><![CDATA[<p>I was helping a friend troubleshoot some of her code today and found the culprit to be a typo in one of her conditional statements:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// var USERID = 12345;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>USERID <span style="color: #339933;">=!</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #006600; font-style: italic;">// code</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Her expression was always resolving to <code>true</code> because she had inverted her <code>!=</code> (&#8220;not-null&#8221;) check which was actually assigning her variable to the return of a statement evaluation. Her mistake would be clearer to understand formatted as such:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// var USERID = 12345;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>USERID <span style="color: #339933;">=</span> <span style="color: #339933;">!</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #006600; font-style: italic;">// code</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Since the inverse of <code>false</code>, <code>null</code>, and <code>NaN</code> is <code>true</code> her conditional statement (also an assignment) would always return <code>true</code>. </p>
<p>Which lead me to thinking, the not operator is a great way to write succinct code. In the right context, using the not operator in the right side of an assignment isn&#8217;t a bad idea.</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/12/31/the-difference-between-and/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improve your jQuery &#8211; 25 excellent tips</title>
		<link>http://readystate4.com/2008/12/16/improve-your-jquery-25-excellent-tips/</link>
		<comments>http://readystate4.com/2008/12/16/improve-your-jquery-25-excellent-tips/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 01:23:04 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/12/16/improve-your-jquery-25-excellent-tips/</guid>
		<description><![CDATA[Here&#8217;s a nice write-up by Jon Hobbs-Smith at tvidesign.com detailing 25 tips on using jQuery as well as regular JavaScript advice. Most of these tips probably aren&#8217;t anything new for the advanced jQuery user (Jon considers himself intermediate, I think that&#8217;s modest), however I love lists like this because there&#8217;s a treasure trove worth of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx"><img src="http://readystate4.com/images/blog/tvidesign_banner.jpg" style="padding-left: 0px;" /></a><br />
Here&#8217;s a nice write-up by Jon Hobbs-Smith at tvidesign.com detailing <a href="http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx">25 tips on using jQuery</a> as well as regular JavaScript advice. Most of these tips probably aren&#8217;t anything new for the advanced jQuery user (Jon considers himself intermediate, I think that&#8217;s modest), however I love lists like this because there&#8217;s a treasure trove worth of experience being shared. Altruism at it&#8217;s best!</p>
<p>I plan on writing more entries on my own tips and tricks with JavaScript and jQuery as well as my methods of debugging in various browsers, compression techniques, etc., but in the meantime, I&#8217;ll just comment on Jon&#8217;s list: </p>
<p><strong>2. Use a [jQuery] cheat sheet</strong></p>
<p>I think <a href="http://visualjquery.com/">Visual jQuery</a> is all you need. And now that there&#8217;s live search and clickable examples it&#8217;s even better.</p>
<p><strong>3. Combine all your scripts and minify them</strong></p>
<p>Dead Edward&#8217;s packer is awesome for minifying, but before I do that, I like to run my code through <a href="http://www.jslint.com/">jSlint</a> to make sure it&#8217;s all valid. I ignore line-break errors as I don&#8217;t agree in many cases that it&#8217;s an issue.</p>
<p>Additionally, when I work on large JS codebases with a lot of other people who may not code as strictly as I do, I like to use <a href="http://www.crockford.com/javascript/jsmin.html">JSmin</a> on the minimal setting (cut-and-paste version <a href="http://fmarcia.info/jsmin/test.html">here</a>). The compression benefit is only slightly less and it preserves single linefeeds preventing JS errors where people forgot to end their statements with a semicolon. It also makes the code easier to read and debug in a production enviornment—great for the times you want the benefits of minification without the side effect of obfuscation.</p>
<p><strong>5. Keep selection operations to a minimum by caching</strong></p>
<p>I just wanted to comment in Ron&#8217;s example where he used:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myList <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myList'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>First, if I ever reference a jQuery collection in my scripts, I like to append the dollar sign character to the beginning of the variable name to signify that it is, in fact, a jQuery collection:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> $myList <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.myList'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It&#8217;s a lot more helpful when you access that variable further down the road and don&#8217;t have to question whether it&#8217;s a jQuery wrapped set, an actual HTML element, or something else.</p>
<p>Secondly, whether you&#8217;re using a JS lib or not, I would never search for an HTML collection by class name alone; What the JavaScript engine is doing in the background is looping through every single element on the page which is very intensive. It would be better to find the closest parent container first or search by specific tag name(s):</p>
<p>Good:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> $myList <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.myList'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//added benefit of knowing the type of element you'll</span>
<span style="color: #006600; font-style: italic;">// receive</span></pre></div></div>

<p>Better:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> $myList <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#closest_parent_id .myList'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// searching the children of a parent</span>
<span style="color: #006600; font-style: italic;">// container instead of all the elements on the page</span></pre></div></div>

<p>Best:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> $myList <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#closest_parent_id ul.myList'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// combination of both above</span></pre></div></div>

<p><strong>19. Use noconflict to rename the jquery object when using other frameworks</strong><br />
<strong>22. How to check if an element exists[...]</strong></p>
<p>As I&#8217;ve probably mentioned before, I always like to use <code>noConflict()</code> in all my projects. I move jQuery to the $j namespace and save <code>$</code> for a shorthand reference to <code>document.getElementById</code> &#8211; I think it&#8217;s what most js developers expect and <code>if($('myDiv))</code> is a lot simpler to write out than <code>if($('#myDiv).length !== 0)</code>  or even <code>if($('#myDiv).length)</code>.</p>
<p>Thanks for the link <a href="http://www.insecureweb.com/">Bryan</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/12/16/improve-your-jquery-25-excellent-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String.toCharCode</title>
		<link>http://readystate4.com/2008/10/27/stringtocharcode/</link>
		<comments>http://readystate4.com/2008/10/27/stringtocharcode/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 15:02:19 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/10/27/stringtocharcode/</guid>
		<description><![CDATA[I noticed that JavaScript has a String.fromCharCode for decoding a sequence of numbers to Unicode values but no String.toCharCode for doing the reverse. So here&#8217;s my rendition: String.prototype.toCharCode = function&#40;&#41;&#123; var r = '', string = this.split&#40;''&#41;; for &#40;var i in string&#41;&#123; r += String.charCodeAt&#40;string&#91;i&#93;&#41; + ','; &#125; return r.substr&#40;0,r.length - 1&#41;; &#125; &#160; 'bob'.toCharCode&#40;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed that JavaScript has a <a href="https://developer.mozilla.org/En/Sandbox/JS/String.fromCharCode" title="Mozilla Definition">String.fromCharCode</a> for decoding a sequence of numbers to Unicode values but no String.toCharCode for doing the reverse. So here&#8217;s my rendition:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toCharCode</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> string <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> string<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        r <span style="color: #339933;">+=</span> String.<span style="color: #660066;">charCodeAt</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">','</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> r.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>r.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #3366CC;">'bob'</span>.<span style="color: #660066;">toCharCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// returns &quot;98,111,98&quot;</span></pre></div></div>

<p class="update" style="padding: 5px; background-color: lightyellow;">
<strong>Update:</strong> version from my good friend <a href="http://blog.nydd.org/about/">Takashi</a> and link to his blog on <a href="http://blog.nydd.org/2008/10/28/process-string/">why it&#8217;s more efficient</a>:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">toCharCode</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> str.<span style="color: #660066;">length</span><span style="color: #339933;">,</span> work <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> len<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        work<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> String.<span style="color: #660066;">charCodeAt</span><span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> work.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">','</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #3366CC;">'bob'</span>.<span style="color: #660066;">toCharCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// returns &quot;98,111,98&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/10/27/stringtocharcode/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Blogging live from jQuery Camp 2008 (@MIT in Boston)</title>
		<link>http://readystate4.com/2008/09/28/blogging-live-from-jquery-camp-2008-mit-in-boston/</link>
		<comments>http://readystate4.com/2008/09/28/blogging-live-from-jquery-camp-2008-mit-in-boston/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 19:02:50 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/09/28/blogging-live-from-jquery-camp-2008-mit-in-boston/</guid>
		<description><![CDATA[So far it&#8217;s been great! Good food, good talks. Here&#8217;s the full topic list. (scroll down to the middle of the page) Took some vids until my camera died, more to come, once I convert &#8216;em and upload &#8216;em. Here&#8217;s the most interesting things I learned so far: jQuery: jQuery does do DOM caching! It [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.readystate4.com/images/blog/jquery.gif" style="float: right; padding: 0 0 5px 5px;" /> So far it&#8217;s been great! Good food, good talks. <a href="http://jquery.com/blog/2008/08/31/jquery-conference-2008-agenda/">Here&#8217;s the full topic list.</a> (scroll down to the middle of the page)</p>
<p>Took some <a href="http://www.youtube.com/watch?v=V-MHHtw6kPY">vids</a> until my camera died, more to come, once I convert &#8216;em and upload &#8216;em. Here&#8217;s the most interesting things I learned so far:</p>
<p>jQuery:</p>
<ul>
<li>jQuery <i>does</i> do DOM caching! It listens for DOM-modified events to clear it&#8217;s internal cache.</li>
<li>That random jquery[<i>random numbers</i>] variable that gets added to the window object is to uniquely identify the jQ instantiation (so you can do things like run multiple instances of jQuery on the same page).</li>
<li>I knew about <a href="http://docs.jquery.com/Traversing/end">.end()</a> but <a href="http://docs.jquery.com/Traversing/andSelf">.andSelf()</a>? Cool!</li>
<li>Nokia and Microsoft join the jQuery camp. Nokia will have jQuery built into their phones (they have some browser-like app environment) $M will have it in their VS/ASP.NET and all future versions of Visual Studio will come with it going foward. <a href="http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/">link</a> <a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx">link</a>.</li>
<li>jQuery is planning to be the first library that doesn&#8217;t use any browser sniffing. They are going to use a &#8220;quirk check&#8221; method of creating some elements that aren&#8217;t added to the page that check for things like if white space gets removed when created an element that starts with a space (IE bug) and others. This way they don&#8217;t have to be constantly updating for new browsers.
<li>John&#8217;s working on a cool new DOM selector API called Sizzle that&#8217;s supposed to be a lot faster. It works by search for the last element in your query up. For example <code>$('div p');</code> would look for all p elements on the page that has a parent div element.</li>
<li>You can use create a namespace when binding events. For example <code>$('#foo').bind('click.bar', func);</code> so it&#8217;s easy to unbind later, and you can encapsulate your events for your own plugins to prevent conflicts.  You can also create your own custom events like <code>$('#foo').bind('apple', func);</code>  and trigger them using <code>$('#foo').trigger('apple');</code> .</li>
<li><code>$('#element').data();</code> lets you bind data to DOM elements (see Data Cache under Internals section <a href="http://remysharp.com/visual-jquery/">here</a>.) Since you can&#8217;t really bind an object to a DOM node jQuery assigns it a random key behind the scenes which it references. This is really handly for storing all kinds of data.
</ul>
<p>jQuery UI:<br />
- Uses the data method above A LOT.<br />
- Lots of enhancements, most interestingly, with drag-and-drop which detects floated elements and allows you to have draggable lists within draggable lists.<br />
- jQuery UI team also working on some experimental stuff for Webkit only (iPhone / Safari / Chrome).<br />
- Theming jQuery UI with <a href="http://ui.jquery.com/themeroller">ThemeRoller</a></p>
<p>Other:<br />
- I&#8217;ve been using this really old but handy site as a jQ reference: <a href="http://visualjquery.com/1.1.2.html">http://visualjquery.com/1.1.2.html</a> made by Yehuda Katz (also a speaker). Asking around on the conference IRC chan I found there&#8217;s a much newer / improved one at <a href="http://remysharp.com/visual-jquery/">http://remysharp.com/visual-jquery/</a> by Remy Sharp. They&#8217;re going to try to update the prior site with the latter.<br />
- Canvas tag is pretty basic but sweet. John Resig gave a whole presentation on it since the using jQuery with Firefox plugins couldn&#8217;t make it.</p>
]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/09/28/blogging-live-from-jquery-camp-2008-mit-in-boston/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a synchronous DWR call</title>
		<link>http://readystate4.com/2008/09/18/making-a-synchronous-dwr-call/</link>
		<comments>http://readystate4.com/2008/09/18/making-a-synchronous-dwr-call/#comments</comments>
		<pubDate>Thu, 18 Sep 2008 18:26:21 +0000</pubDate>
		<dc:creator>Mauvis</dc:creator>
				<category><![CDATA[DWR]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://readystate4.com/2008/09/18/making-a-synchronous-dwr-call/</guid>
		<description><![CDATA[It took me about half an hour of Googling to find this, and I couldn&#8217;t readily find this in the DWR documentation. Hopefully this may save someone some time: To make a DWR call synchronous (meaning browser-blocking) you must pass an object as one of the arguments of your DWR call with a property async [...]]]></description>
			<content:encoded><![CDATA[<p>It took me about half an hour of Googling to find this, and I couldn&#8217;t readily find this in the <a href="http://directwebremoting.org/dwr/documentation">DWR documentation</a>. Hopefully this may save someone some time:</p>
<p>To make a DWR call synchronous (meaning browser-blocking) you must pass an object as one of the arguments of your DWR call with a property <code>async</code> set to <code>false</code>.</p>
<p>I needed this feature in project where a collection object sends out a call for more data if it didn&#8217;t have it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
_getData<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>offset<span style="color: #339933;">,</span> limit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r<span style="color: #339933;">;</span>
    DWRcomponent.<span style="color: #660066;">getComments</span><span style="color: #009900;">&#40;</span>offset<span style="color: #339933;">,</span> limit<span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> 
        async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        callback<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            r <span style="color: #339933;">=</span> toJSON<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> s <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
    <span style="color: #000066; font-weight: bold;">return</span> r<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
...</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://readystate4.com/2008/09/18/making-a-synchronous-dwr-call/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

