<?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>rob.robb.ns</title>
	<atom:link href="http://robrobbins.info/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://robrobbins.info</link>
	<description>code, etc...</description>
	<lastBuildDate>Sat, 10 Jul 2010 19:33:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The Roll Your Own Series From JSMag</title>
		<link>http://robrobbins.info/?p=357</link>
		<comments>http://robrobbins.info/?p=357#comments</comments>
		<pubDate>Sat, 10 Jul 2010 19:31:19 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jsmag]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=357</guid>
		<description><![CDATA[I finally put together a page to host my articles published in JSMag for those of you who might have missed them. The articles, titled &#8220;Roll Your Own&#8221; and dealing with the proposition of creating a custom JavaScript library from scratch, will run about a month or so behind the magazine&#8217;s releases so if you ]]></description>
			<content:encoded><![CDATA[<p>I finally put together a <a href="http://robrobbins.info/?page_id=317">page</a> to host my articles published in <a href="http://www.jsmag.com">JSMag</a> for those of you who might have missed them. The articles, titled &#8220;Roll Your Own&#8221; and dealing with the proposition of creating a custom JavaScript library from scratch, will run about a month or so behind the magazine&#8217;s releases so if you like the columns go pick up the current issue <a href="http://www.jsmag.com/latest">here</a>. </p>
<p><a href="http://robrobbins.info/?page_id=317">The &#8216;Roll Your Own&#8217; columns.</a></p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=357&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=357&amp;title=The+Roll+Your+Own+Series+From+JSMag" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=357&amp;title=The+Roll+Your+Own+Series+From+JSMag" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=357&amp;title=The+Roll+Your+Own+Series+From+JSMag&amp;desc=I%20finally%20put%20together%20a%20page%20to%20host%20my%20articles%20published%20in%20JSMag%20for%20those%20of%20you%20who%20might%20have%20missed%20them.%20The%20articles%2C%20titled%20%22Roll%20Your%20Own%22%20and%20dealing%20with%20the%20proposition%20of%20creating%20a%20custom%20JavaScript%20library%20from%20scratch%2C%20will%20run%20about%20a%20month%20or%20so%20behind%20the%20magazine%27s%20releases%20so" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=357&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=357&amp;bm_description=The+Roll+Your+Own+Series+From+JSMag&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=357&amp;title=The+Roll+Your+Own+Series+From+JSMag" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=357&amp;title=The+Roll+Your+Own+Series+From+JSMag" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=357&amp;title=The+Roll+Your+Own+Series+From+JSMag" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=357" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=The+Roll+Your+Own+Series+From+JSMag+-+http://b2l.me/97w56&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=357&amp;t=The+Roll+Your+Own+Series+From+JSMag" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=357</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Added Crockford&#8217;s JSLint to the &#8216;javascript-tools&#8217; Textmate Bundle</title>
		<link>http://robrobbins.info/?p=308</link>
		<comments>http://robrobbins.info/?p=308#comments</comments>
		<pubDate>Thu, 01 Jul 2010 19:15:09 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Textmate]]></category>
		<category><![CDATA[Lint]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=308</guid>
		<description><![CDATA[The other day I forked the excellent javascript-tools Textmate bundle in order to add Douglas Crockford&#8217;s JSLint as an option to go along with JavaScriptLint and the Closure Compiler. You can find it here. I want to look at using Safari&#8217;s compiler in order to alleviate the Rhino dependancy, ad possibly include the newest jslint.js ]]></description>
			<content:encoded><![CDATA[<p>The other day I forked the excellent <a href="http://github.com/subtleGradient/javascript-tools.tmbundle">javascript-tools</a> Textmate bundle in order to add Douglas Crockford&#8217;s JSLint as an option to go along with JavaScriptLint and the Closure Compiler. You can find it <a href="http://github.com/robrobbins/javascript-tools.tmbundle">here</a>. I want to look at using Safari&#8217;s compiler in order to alleviate the Rhino dependancy, ad possibly include the newest jslint.js with a config file but, unfortunately, don&#8217;t have time at the moment. I will soon, but until then this early version at least fits in functionally and aesthetically with the rest of the bundle. Rhino is expected to be installed, as well as jslint,js to be located in &#8216;~/Library/JSLint&#8217;.</p>
<p>The enterprising can just open the bundle contents and hack away at the dclint.rb file to change any paths or dependencies. Hey look, screenshots!</p>
<div id="attachment_312" class="wp-caption aligncenter" style="width: 305px"><a href="http://robrobbins.info/wp-content/uploads/2010/07/Screen-shot-2010-07-01-at-12.17.35-PM.png"><img src="http://robrobbins.info/wp-content/uploads/2010/07/Screen-shot-2010-07-01-at-12.17.35-PM.png" alt="Lint Menu" title="&lt;ctrl&gt; + &lt;shift&gt; + v ..." width="295" height="82" class="size-full wp-image-312" /></a><p class="wp-caption-text">Added entry into the lint options menu</p></div>
<div id="attachment_313" class="wp-caption aligncenter" style="width: 310px"><a href="http://robrobbins.info/wp-content/uploads/2010/07/Screen-shot-2010-07-01-at-12.19.47-PM.png"><img src="http://robrobbins.info/wp-content/uploads/2010/07/Screen-shot-2010-07-01-at-12.19.47-PM-300x181.png" alt="Jslint output" title="JSLint Output Window" width="300" height="181" class="size-medium wp-image-313" /></a><p class="wp-caption-text">Fits into the bundle aesthetics</p></div>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=308&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=308&amp;title=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=308&amp;title=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=308&amp;title=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle&amp;desc=The%20other%20day%20I%20forked%20the%20excellent%20javascript-tools%20Textmate%20bundle%20in%20order%20to%20add%20Douglas%20Crockford%27s%20JSLint%20as%20an%20option%20to%20go%20along%20with%20JavaScriptLint%20and%20the%20Closure%20Compiler.%20You%20can%20find%20it%20here.%20I%20want%20to%20look%20at%20using%20Safari%27s%20compiler%20in%20order%20to%20alleviate%20the%20Rhino%20dependancy%2C%20ad%20possi" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=308&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=308&amp;bm_description=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=308&amp;title=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=308&amp;title=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=308&amp;title=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=308" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle+-+http://b2l.me/75h9j&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=308&amp;t=Added+Crockford%27s+JSLint+to+the+%27javascript-tools%27+Textmate+Bundle" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=308</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RML.post(#2)</title>
		<link>http://robrobbins.info/?p=291</link>
		<comments>http://robrobbins.info/?p=291#comments</comments>
		<pubDate>Sun, 11 Apr 2010 03:44:42 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[RML]]></category>
		<category><![CDATA[Templating]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=291</guid>
		<description><![CDATA[Quick example of a header section of a web page that contains a few form elements done with RML: &#160; markup: &#123; &#160; &#160; header: function&#40;&#41; &#123; &#160; &#160; &#160; var $header = RML.div&#40;&#123; &#160; &#160; &#160; &#160; id:'header', &#160; &#160; &#160; &#160; content: RML.h1&#40;'The Chat'&#41; + &#160; &#160; &#160; &#160; RML.hr&#40;&#41; + &#160; &#160; ]]></description>
			<content:encoded><![CDATA[<p>Quick example of a header section of a web page that contains a few form elements done with RML:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; markup<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; header<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><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> $header <span style="color: #339933;">=</span> RML.<span style="color: #660066;">div</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; id<span style="color: #339933;">:</span><span style="color: #3366CC;">'header'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> RML.<span style="color: #660066;">h1</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'The Chat'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RML.<span style="color: #660066;">hr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; RML.<span style="color: #660066;">div</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'message-form'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; content<span style="color: #339933;">:</span> RML.<span style="color: #660066;">textarea</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'txt-message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id<span style="color: #339933;">:</span><span style="color: #3366CC;">'txt-message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rows<span style="color: #339933;">:</span><span style="color: #3366CC;">'4'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cols<span style="color: #339933;">:</span><span style="color: #3366CC;">'60'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> RML.<span style="color: #660066;">input</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id<span style="color: #339933;">:</span><span style="color: #3366CC;">'btn-send-message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'btn-send-message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">:</span><span style="color: #3366CC;">'Send Message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> RML.<span style="color: #660066;">input</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id<span style="color: #339933;">:</span><span style="color: #3366CC;">'btn-clear-message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'btn-clear-message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">:</span><span style="color: #3366CC;">'Clear Message'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> RML.<span style="color: #660066;">input</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span><span style="color: #3366CC;">'button'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id<span style="color: #339933;">:</span><span style="color: #3366CC;">'btn-logout'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">name</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'btn-logout'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #339933;">:</span><span style="color: #3366CC;">'Log Out'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> $header<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">//end header</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>I&#8217;m using it here in a larger object literal method which can be called with a refinement like so:</p>
<dl id="attachment_293" class="wp-caption aligncenter" style="width: 460px;">
<dt class="wp-caption-dt"><a href="http://robrobbins.info/wp-content/uploads/2010/04/Screen-shot-2010-04-10-at-8.36.25-PM.png"><img class="size-full wp-image-293" title="The rendered HTML" src="http://robrobbins.info/wp-content/uploads/2010/04/Screen-shot-2010-04-10-at-8.36.25-PM.png" alt="HTML rendered by the RML methods" width="450" height="170" /></a></dt>
<dd class="wp-caption-dd">The rendered HTML</dd>
</dl>
<p>Get the code at <a href="http://github.com/robrobbins/RML">github</a> or <a href="http://robrobbins.info/?page_id=267">here on the RML page</a>. I&#8217;ll post more later this week&#8230;</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=291&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=291&amp;title=RML.post%28%232%29" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=291&amp;title=RML.post%28%232%29" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=291&amp;title=RML.post%28%232%29&amp;desc=Quick%20example%20of%20a%20header%20section%20of%20a%20web%20page%20that%20contains%20a%20few%20form%20elements%20done%20with%20RML%3A%0D%0A%0D%0A%0D%0A%20%20markup%3A%20%7B%0D%0A%20%20%20%20header%3A%20function%28%29%20%7B%0D%0A%20%20%20%20%20%20var%20%24header%20%3D%20RML.div%28%7B%0D%0A%20%20%20%20%20%20%20%20id%3A%27header%27%2C%0D%0A%20%20%20%20%20%20%20%20content%3A%20RML.h1%28%27The%20Chat%27%29%20%2B%0D%0A%20%20%20%20%20%20%20%20RML.hr%28%29%20%2B%0D%0A%20%20%20%20%20%20%20%20RML.div%28%7B%0D%0A%20%20%20%20%20%20%20%20%20%20class%3A%27message-for" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=291&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=291&amp;bm_description=RML.post%28%232%29&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=291&amp;title=RML.post%28%232%29" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=291&amp;title=RML.post%28%232%29" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=291&amp;title=RML.post%28%232%29" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=291" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=RML.post%28%232%29+-+http://b2l.me/n22jn&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=291&amp;t=RML.post%28%232%29" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=291</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title> Generate Markup with JavaScript</title>
		<link>http://robrobbins.info/?p=284</link>
		<comments>http://robrobbins.info/?p=284#comments</comments>
		<pubDate>Thu, 08 Apr 2010 14:43:32 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Templating]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=284</guid>
		<description><![CDATA[I am going to blog more in depth this weekend about this little markup generating JavaScript that I&#8217;m working on. I know there are others, but what fun is that? Basically, RML will generate tag-based markup like HTML and XML from JavaScript. I have been using it for templating alone and within a larger Ext.js ]]></description>
			<content:encoded><![CDATA[<p>I am going to blog more in depth this weekend about <a href="http://robrobbins.info/?page_id=267">this little markup generating JavaScript</a> that I&#8217;m working on. I know there are others, but what fun is that? Basically, RML will generate tag-based markup like HTML and XML from JavaScript. I have been using it for templating alone and within a larger Ext.js application with pleasing results. I just need to add more tag shortcuts to the object, but it is very usable now. Get it <a href="http://robrobbins.info/?page_id=267">here</a> or at <a href="http://github.com/robrobbins/RML">my github repo</a>.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=284&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=284&amp;title=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=284&amp;title=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=284&amp;title=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E&amp;desc=I%20am%20going%20to%20blog%20more%20in%20depth%20this%20weekend%20about%20this%20little%20markup%20generating%20JavaScript%20that%20I%27m%20working%20on.%20I%20know%20there%20are%20others%2C%20but%20what%20fun%20is%20that%3F%20Basically%2C%20RML%20will%20generate%20tag-based%20markup%20like%20HTML%20and%20XML%20from%20JavaScript.%20I%20have%20been%20using%20it%20for%20templating%20alone%20and%20within%20a%20lar" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=284&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=284&amp;bm_description=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=284&amp;title=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=284&amp;title=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=284&amp;title=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=284" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E+-+http://b2l.me/nrmmq&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=284&amp;t=%3CRML%3E+Generate+Markup+with+JavaScript%3C%2FRML%3E" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=284</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSLint, Vim, and Windows XP</title>
		<link>http://robrobbins.info/?p=245</link>
		<comments>http://robrobbins.info/?p=245#comments</comments>
		<pubDate>Wed, 13 Jan 2010 18:40:17 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[Jslint JavaScript Vim]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=245</guid>
		<description><![CDATA[Just a quick post about integrating JSLint with Vim on a Windows XP machine. I had posted awhile back about integrating JavascriptLint with Vim on XP, but while re-reading The Good Parts I got the urge to revisit JSLint just to revel in the Crockfordness of it all&#8230; First off, get Jesse Hallett&#8217;s excellent jslint.vim ]]></description>
			<content:encoded><![CDATA[<p>Just a quick post about integrating JSLint with Vim on a Windows XP machine. I had <a href="http://robrobbins.info/?p=153">posted</a> awhile back about integrating <a href="http://robrobbins.info/?p=153">JavascriptLint with Vim on XP</a>, but while re-reading The <a href="http://oreilly.com/catalog/9780596517748">Good Parts</a> I got the urge to revisit <a href="http://www.jslint.com/">JSLint</a> just to revel in the Crockfordness of it all&#8230;
<p>First off, get Jesse Hallett&#8217;s excellent jslint.vim plugin <a href="http://www.vim.org/scripts/script.php?script_id=2729">here</a>. I installed this on my Fedora box without a hitch (well, the only hitch was figuring out the name of the Spidermonkey package for Fedora 12, &#8216;js-devel&#8217; I believe it was) but my work XP machine would spit this out when attempting a :jslint command:</p>
<div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Error detected <span style="color: #804040;">while</span> processing <span style="color: #804040;">function</span> <span style="color: #000000;">&lt;</span>SNR<span style="color: #000000;">&gt;</span><span style="color: #000000; font-weight:bold;">17</span>_JSLint<span style="color: #000000;">:</span><br />
<span style="color: #25BB4D;">line</span> &nbsp;<span style="color: #000000; font-weight:bold;">43</span><span style="color: #000000;">:</span><br />
E484<span style="color: #000000;">:</span> Con<span style="color: #C5A22D;">'t open file C:<span style="">\.</span>..<span style="">\.</span>..<span style="">\.</span>..<span style="">\.</span>..<span style="">\V</span>Io1F3B.tmp</span></div></div>
<p>It&#8217;s obvious that some paths (literally, figuratively) were getting crossed somewhere <i>(*Note you may also want to attempt to use cscript from the command line just to make sure it is, in fact, installed and working. I did, and mine was*.)</i></p>
<p> In my experience the first place to check for errors with Vim plugins is the PATH so I opened up Jesse&#8217;s plugin and focused on this section (lines 41-59 on his github repo version):</p>
<div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>plugin_path = <span style="color: #C5A22D;">'&quot;'</span> <span style="color: #000000;">.</span> <span style="color: #25BB4D;">expand</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;~/&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">.</span> <span style="color: #C5A22D;">'&quot;'</span><br />
&nbsp; <span style="color: #804040;">if</span> <span style="color: #25BB4D;">has</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;win32&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>cmd = <span style="color: #C5A22D;">'cscript /NoLogo '</span><br />
&nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>plugin_path = s<span style="color: #000000;">:</span>plugin_path <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;vimfiles&quot;</span><br />
&nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>runjslint_ext = <span style="color: #C5A22D;">'wsf'</span><br />
&nbsp; <span style="color: #804040;">else</span><br />
&nbsp; &nbsp; <span style="color: #804040;">if</span> <span style="color: #25BB4D;">has</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;gui_macvim&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&amp;&amp;</span> <span style="color: #25BB4D;">filereadable</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc'</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>cmd = <span style="color: #C5A22D;">'/System/Library/Frameworks/JavaScriptCore.framework/Resources/jsc'</span><br />
&nbsp; &nbsp; <span style="color: #804040;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>cmd = <span style="color: #C5A22D;">'js'</span><br />
&nbsp; &nbsp; <span style="color: #804040;">endif</span><br />
&nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>plugin_path = s<span style="color: #000000;">:</span>plugin_path <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;.vim&quot;</span><br />
&nbsp; &nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>runjslint_ext = <span style="color: #C5A22D;">'js'</span><br />
&nbsp; <span style="color: #804040;">endif</span><br />
&nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>plugin_path = s<span style="color: #000000;">:</span>plugin_path <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;/plugin/jslint/&quot;</span><br />
&nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>cmd = <span style="color: #C5A22D;">&quot;cd &quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>plugin_path <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; &amp;&amp; &quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>cmd <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; &quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>plugin_path<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\ <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;runjslint.&quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>runjslint_ext<br />
&nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>jslintrc_file = <span style="color: #25BB4D;">expand</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'~/.jslintrc'</span><span style="color: #000000;">&#41;</span></div></div>
<p>Here&#8217;s the version I ended up with after experimenting for awhile:</p>
<div class="codecolorer-container vim twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vim codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>plugin_path = <span style="color: #C5A22D;">'&quot;'</span> <span style="color: #000000;">.</span> <span style="color: #25BB4D;">expand</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">&quot;C:/Program Files/Vim/vimfiles&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">.</span> <span style="color: #C5A22D;">'&quot;'</span><br />
&nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>cmd = <span style="color: #C5A22D;">'cscript /NoLogo '</span><br />
&nbsp; <span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>runjslint_ext = <span style="color: #C5A22D;">'wsf'</span><br />
<span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>plugin_path = s<span style="color: #000000;">:</span>plugin_path <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;/plugin/jslint/&quot;</span><br />
<span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>cmd = <span style="color: #C5A22D;">&quot;cd &quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>plugin_path <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; &amp;&amp; &quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>cmd <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; &quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>plugin_path <br />
&nbsp; &nbsp; &nbsp; &nbsp;\ <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;runjslint.&quot;</span> <span style="color: #000000;">.</span> s<span style="color: #000000;">:</span>runjslint_ext<br />
<span style="color: #804040;">let</span> s<span style="color: #000000;">:</span>jslintrc_file = <span style="color: #25BB4D;">expand</span><span style="color: #000000;">&#40;</span><span style="color: #C5A22D;">'C:/Program Files/Vim/_jslintrc'</span><span style="color: #000000;">&#41;</span></div></div>
<p>So, I ended up changing 3 things:</p>
<ul>
<li>Remove tests for which OS is being used</li>
<li>Explicitly state the plugin path</li>
<li>Changed the name and path of the jslintrc file</li>
</ul>
<p>First, since we know this is for XP, the tests for Win32, Mac and &#8216;Nix are not needed. Second, there are more compact and portable ways to specify this path, but posting it this way makes it easy to adapt to your system path. Third, On my XP system my .vimrc is actually _vimrc and I keep it here in the vimfiles directory so it made sense to me to do the same with a jslintrc.
</p>
<p>
Speaking of the _jslintrc, it looks like the &#8216;fulljslint.js&#8217; file is updated quite a bit on the jslint.com website, and allows for more options in the jslintrc file. I need to experiment with that next</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=245&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=245&amp;title=JSLint%2C+Vim%2C+and+Windows+XP" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=245&amp;title=JSLint%2C+Vim%2C+and+Windows+XP" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=245&amp;title=JSLint%2C+Vim%2C+and+Windows+XP&amp;desc=Just%20a%20quick%20post%20about%20integrating%20JSLint%20with%20Vim%20on%20a%20Windows%20XP%20machine.%20I%20had%20posted%20awhile%20back%20about%20integrating%20JavascriptLint%20with%20Vim%20on%20XP%2C%20but%20while%20re-reading%20The%20Good%20Parts%20I%20got%20the%20urge%20to%20revisit%20JSLint%20just%20to%20revel%20in%20the%20Crockfordness%20of%20it%20all...%0D%0AFirst%20off%2C%20get%20Jesse%20Hallett%27s%20" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=245&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=245&amp;bm_description=JSLint%2C+Vim%2C+and+Windows+XP&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=245&amp;title=JSLint%2C+Vim%2C+and+Windows+XP" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=245&amp;title=JSLint%2C+Vim%2C+and+Windows+XP" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=245&amp;title=JSLint%2C+Vim%2C+and+Windows+XP" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=245" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=JSLint%2C+Vim%2C+and+Windows+XP+-+http://b2l.me/dm7t8&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=245&amp;t=JSLint%2C+Vim%2C+and+Windows+XP" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=245</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>X JavaScript: Detecting, Adding and Removing Class Names</title>
		<link>http://robrobbins.info/?p=198</link>
		<comments>http://robrobbins.info/?p=198#comments</comments>
		<pubDate>Thu, 31 Dec 2009 19:29:44 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[X]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=198</guid>
		<description><![CDATA[X.removeClass(X.addClass(X.get('div', X.get('#stripes')), 'slate'), 'green') FTW!]]></description>
			<content:encoded><![CDATA[<p>I want to post a quick bit here about three methods I use in the X library which make use of element classnames. First a method to detect if an element has a given class:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">hasClass</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> $class<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> pattern <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(^| )&quot;</span> <span style="color: #339933;">+</span> $class <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;( |$)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//ternary to choose</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> pattern.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>element.<span style="color: #660066;">className</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Breaking that down, you have the function taking two arguments. One, the element to check for the presence of the class name and two, the class name itself. Next, a RegEx is defined which will attempt to match the class name you passed in. The RexEx itself is made so that a portion of a string can be matched because of the way that classnames are applied to elements on the DOM, i.e. &#8220;spam eggs vikings&#8221;. Last, the ternary (return pattern.test&#8230;) executes depending on what the test() method returns. Remember, test() is a function of the RegEx object which returns a bool depending on a positive(or lack of) match. Test() is going to return a &#8216;true&#8217; of the class name is found, &#8216;false&#8217; if not.If you are unfamiliar with ternary operators,  let&#8217;s explain by looking at what an if/else doing the same thing would look like.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>pattern.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>element.<span style="color: #660066;">className</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>That works, but it&#8217;s not the lean and mean js machine we are going for here. Now, the one line of the ternary:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">return pattern.test(element.className) ? true : false;</div></div>
<p>And it works like this:<br />
<i>an action -something to evaluate- ? do if true : do if false</i>
</p>
<p>
So, in practice you could check if an element had a class name by calling:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span>myElement<span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>hasClass is going to return a Bool though, so usually you will use it as part of an expression:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span>myElement<span style="color: #339933;">,</span> <span style="color: #3366CC;">'myClass'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">do</span> stuff <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #003366; font-weight: bold;">true</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>I rarely use hasClass outright, but the next function does.
</p>
<p>
To add a class to a single element or a collection of elements we have this:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">addClass</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> $class<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//is the element array-like?</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>element.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</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> element.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>X.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> $class<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">+=</span> element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">?</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $class <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>$class<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//not array-like</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>X.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> $class<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; element.<span style="color: #660066;">className</span> <span style="color: #339933;">+=</span> element.<span style="color: #660066;">className</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">?</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $class <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">+</span>$class<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> element<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
</p>
<p>In Summary, addClass takes 2 arguments, an element and a class name, checks to see if the element passed in is a single element or a collection of elements, then checks the element(s) to see if they have the passed in class name (via hasClass). If not, element is then checked for the presence of any other classes. Why? If there is another class name already assigned to the element(s) you need to insert a space in front of the new class being appended. Finally the class name you passed in is appended (as long as it&#8217;s not already there) and the element is returned. Let&#8217;s combine the <a href="http://robrobbins.info/?p=97">get method</a> with this in a couple of practical examples:
</p>
<p>
Say you have an HTML page with these four divs contained in a fifth div:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stripes&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div1&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div2&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div3&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div4&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
<p>And maybe some styles to go with them:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #cc00cc;">#div1</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#div2</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#div3</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#div4</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
.<span style="color: #993333;">green</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#7f9e7b</span><span style="color: #00AA00;">;</span> <br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.slate</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#424242</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.grey</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#888</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>So, on a goofy little test page you might have this:<br />
<div id="attachment_218" class="wp-caption aligncenter" style="width: 560px"><img src="http://robrobbins.info/wp-content/uploads/2009/12/test11.png" alt="Classless divs" title="Classless divs" width="550" height="192" class="aligncenter size-full wp-image-218" /><p class="wp-caption-text">Classless divs</p></div><br />
Since the <a href="http://robrobbins.info/?p=97">get method</a> returns either a single element or a collection of them, and since our new addClass function can handle either scenario you could grab all those divs and set their background to say, green, in one pass:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stripes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Giving you this:<br />
<div id="attachment_220" class="wp-caption aligncenter" style="width: 560px"><img src="http://robrobbins.info/wp-content/uploads/2009/12/test2.png" alt="Now with some class (green to be exact)" title="With Class" width="550" height="192" class="size-full wp-image-220" /><p class="wp-caption-text">Now with some class (green to be exact)</p></div>
</p>
<p>
Breaking that expression down, recall that the <a href="http://robrobbins.info/?p=97">get method</a> will allow you to pass in a &#8216;context&#8217; to restrain searching. Because I only wanted the divs inside of the div with the id of &#8220;stripes&#8221; I passed it (&#8216;#stripes&#8217;) in along with the search for the generic &#8216;div&#8217; tagname:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> divs <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stripes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>You can break this up into 2 expressions if you want:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> stripes <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stripes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> divs <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> stripes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>After getting the elements, I sent them to addClass. If you used the more verbose code above you would have:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> stripes <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stripes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> divs <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> stripes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
X.<span style="color: #660066;">addclass</span><span style="color: #009900;">&#40;</span>divs<span style="color: #339933;">,</span> <span style="color: #3366CC;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>In these examples the fact that addClass returns the element passed in is of no consequence. JavaScript functions always return a value, even if one is not specified (undefined in that case), so specifying element as the return value could just be ignored, but we are going to use it next to combine with removeClass.
</p>
<p>
Here is that removeClass function:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">removeClass</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> $class<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> pattern <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(^| )&quot;</span> <span style="color: #339933;">+</span> $class <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;( |$)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//is element array-like?</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>element.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</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> element.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>pattern<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;$1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> element<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">className</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ $/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//nope</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; element.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> element.<span style="color: #660066;">className</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span>pattern<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;$1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; element.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> element.<span style="color: #660066;">className</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/ $/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> element<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Before doing something pedestrian like just removing the &#8216;green&#8217; classnames from the divs inside of &#8216;stripes&#8217; let&#8217;s swing for the fence and remove the classnames, then add new ones all in one go. weeee!:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stripes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Now that test page would look like:<br />
<div id="attachment_227" class="wp-caption aligncenter" style="width: 560px"><img src="http://robrobbins.info/wp-content/uploads/2009/12/test3.png" alt="Class changed to &#039;slate&#039;" title="Gray divs" width="550" height="193" class="size-full wp-image-227" /><p class="wp-caption-text">Class changed to 'slate'</p></div>
</p>
<p>
This works because of the fact that addClass is returning the element list containing all of the divs we want removeClass to operate on. If you look close you&#8217;ll notice that all you needed to do was to take the previous expression we used for adding the green classes at once:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #339933;">,</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#stripes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>and wrapping it with the removeClass call:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>previous expression<span style="color: #339933;">--</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>There&#8217;s more to breakdown, but not too much. The removeClass function just uses the same methodology that addClass does for checking if element is an array-like object (has a length?) then looks for the passed in classname with a RegExp which will replace a match with an empty string using the &#8216;$1&#8242; backreference (the second call to replace makes sure no whitespace is left over). Finally the element is returned, just like addClass. And, yes, you could invert the order to addClass(removeClass()), it doesn&#8217;t matter
</p>
<p>
All of these examples could have, obviously, been used on single elements. X.get, X.addClass and X.removeClass will take care of that for you. So if you wanted to change the second div back to green you would go:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#div2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'green'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Notice there is no need to specify a context when using an id (it should be unique).</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=198&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=198&amp;title=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=198&amp;title=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=198&amp;title=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names&amp;desc=X.removeClass%28X.addClass%28X.get%28%27div%27%2C%20X.get%28%27%23stripes%27%29%29%2C%20%27slate%27%29%2C%20%27green%27%29%20FTW%21" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=198&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=198&amp;bm_description=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=198&amp;title=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=198&amp;title=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=198&amp;title=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=198" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names+-+http://b2l.me/cu2gn&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=198&amp;t=X+JavaScript%3A+Detecting%2C+Adding+and+Removing+Class+Names" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=198</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Emacs, CEDET, Windows and GIT. Success!</title>
		<link>http://robrobbins.info/?p=187</link>
		<comments>http://robrobbins.info/?p=187#comments</comments>
		<pubDate>Thu, 03 Dec 2009 20:00:39 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Emacs]]></category>
		<category><![CDATA[CEDET]]></category>
		<category><![CDATA[GIT]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=187</guid>
		<description><![CDATA[Quick post here because I&#8217;ll probably need this myself later. I didn&#8217;t have any problems getting Emacs, CEDET, and ECB up and running on my Fedora box but my WinXP machine refused to byte-compile the cedet-build.el lisp file. This looks to be a common problem for folks using Emacs on Win with CEDET&#8217;s latest files ]]></description>
			<content:encoded><![CDATA[<p>Quick post here because I&#8217;ll probably need this myself later. I didn&#8217;t have any problems getting Emacs, CEDET, and ECB up and running on my Fedora box but my WinXP machine refused to byte-compile the cedet-build.el lisp file. This looks to be a common problem for folks using Emacs on Win with CEDET&#8217;s latest files from Sourceforge. After seeing that some people had success after getting the newest CVS repository files for CEDET I immediately searched for a git mirror (not wanting to have to use CVS) and found it <a href="http://github.com/emacs-pkg-mirrors/cedet/">here</a></p>
<p>The instructions on <a href="http://cedet.sourceforge.net/setup.shtml">CEDET&#8217;s website</a> are:<br />
<i>&#8220;If you are on Windows, and or don&#8217;t have make for some reason, you can use CEDET&#8217;s built in project management system to force CEDET to bootstrap itself. You can initiate the build process like this:&#8221;</i></p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; cd path/to/cedetdirectory<br />
&nbsp; &nbsp; emacs -Q -l cedet-build.el -f cedet-build</div></div>
<p>Since the Windows version of Emacs is in a self contained directory (mine is emacs-23.1/) with an executable named &#8216;runemacs.exe&#8217; in the folder &#8216;emacs-23.1/bin/&#8217; on my Desktop, I just changed the command to fit the environment properly. Opening a Cygwin bash prompt I did this:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ cd ~/Desktop/cedet/<br />
$ ~/Desktop/emacs-23.1/bin/runemacs.exe -Q -l cedet-build.el -f cedet-build</div></div>
</p>
<p>AND the freezing on step 6, setting up EDE goes away. ECB can now be setup<br />


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=187&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=187&amp;title=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=187&amp;title=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=187&amp;title=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21&amp;desc=Quick%20post%20here%20because%20I%27ll%20probably%20need%20this%20myself%20later.%20I%20didn%27t%20have%20any%20problems%20getting%20Emacs%2C%20CEDET%2C%20and%20ECB%20up%20and%20running%20on%20my%20Fedora%20box%20but%20my%20WinXP%20machine%20refused%20to%20byte-compile%20the%20cedet-build.el%20lisp%20file.%20This%20looks%20to%20be%20a%20common%20problem%20for%20folks%20using%20Emacs%20on%20Win%20with%20CEDET%27" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=187&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=187&amp;bm_description=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=187&amp;title=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=187&amp;title=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=187&amp;title=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=187" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21+-+http://b2l.me/cu2gp&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=187&amp;t=Emacs%2C+CEDET%2C+Windows+and+GIT.+Success%21" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=187</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating JavaScriptLint With Vim On Windows</title>
		<link>http://robrobbins.info/?p=153</link>
		<comments>http://robrobbins.info/?p=153#comments</comments>
		<pubDate>Thu, 05 Nov 2009 01:02:47 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Vim]]></category>
		<category><![CDATA[Jslint JavaScript Vim]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=153</guid>
		<description><![CDATA[I use Vim to code JavaScript on my work machine, a PC running WinXp. Looking around for a way to integrate a good lint program to catch typical .js errors I found JavaScriptLint.vim. The instructions there are simple, drop the script in your vim/plugins folder after the jsl.exe program has been installed. That executable, the ]]></description>
			<content:encoded><![CDATA[<p>
I use Vim to code JavaScript on my work machine, a PC running WinXp. Looking around for a way to integrate a good lint program to catch typical .js errors I found <a href="http://www.vim.org/scripts/script.php?script_id=2578">JavaScriptLint.vim</a>. The instructions there are simple, drop the script in your vim/plugins folder after the <a href="http://www.javascriptlint.com/">jsl.exe</a> program has been installed. That executable, the <a href="http://www.javascriptlint.com/">javascriptlint</a> program itself, has good documentation for <a href="http://blogs.linux.ie/kenguest/2007/03/18/integrating-javascript-lint-with-vim/">Vim integration on Linux</a> (which works well btw) but none for Windows. Here is what I did:</p>
<ul>
<li>First, download the version for windows <a href="http://www.javascriptlint.com/download/jsl-0.3.0-win32.zip">here</a></li>
<li>Extract that .zip anywhere, doesn&#8217;t matter</li>
<li>From the extracted folder grab the jsl.exe and jsl.default.conf files and put them in your C:\Program Files\Vim\Vim72 folder (If you&#8217;re using Vim 7.2, I would assume other versions have a similar folder structure. It&#8217;s the same directory the gvim.exe, vim.exe and others are in).</li>
<li>Drop the <a href="http://www.vim.org/scripts/script.php?script_id=2578">JavaScriptLint.vim</a> file in C:\Program Files\Vim\vim72\plugin</li>
</ul>
<p>Now, you&#8217;re almost done. Open up the jsl.default.conf file in a text editor and in the &#8216;Defining Identifiers&#8217; section enable &#8216;always_use_option_explicit&#8217; like so:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">### Defining identifiers<br />
# By default, &quot;option explicit&quot; is enabled on a per-file basis.<br />
# To enable this for all files, use &quot;+always_use_option_explicit&quot;<br />
+always_use_option_explicit</div></div>
<p>Also, just below the &#8216;common uses for webpages might be: line I added these, a la <a href="http://blogs.linux.ie/kenguest/2007/03/18/integrating-javascript-lint-with-vim/">Ken Guest</a>:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"># Common uses for webpages might be:<br />
+define ActiveXObject<br />
+define addEventListener<br />
+define alert<br />
+define attributes<br />
+define blur<br />
+define childNodes<br />
+define click<br />
+define clearTimeout<br />
+define dispatchEvent<br />
+define document<br />
+define firstChild<br />
+define focus<br />
+define Image<br />
+define item<br />
+define lastChild<br />
+define localName<br />
+define namespaceURI<br />
+define navigator<br />
+define nextSibling<br />
+define nodeName<br />
+define nodeType<br />
+define nodeValue<br />
+define ownerDocument<br />
+define parent<br />
+define parentNode<br />
+define prefix<br />
+define previousSibling<br />
+define removeEventListener<br />
+define screen<br />
+define scrollIntoView<br />
+define setTimeout<br />
+define tagName<br />
+define window<br />
+define XMLHttpRequest</div></div>
<p>The last thing I did, and this just because it looked like the correct thing to do, was I commented out the &#8216;files&#8217; section test file since Vim is sending the file for me (and since I didn&#8217;t drop that file in from the extracted folder anyway&#8230;):</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">### Files<br />
# Specify which files to lint<br />
# Use &quot;+recurse&quot; to enable recursion (disabled by default).<br />
# To add a set of files, use &quot;+process FileName&quot;, &quot;+process Folder\Path\*.js&quot;,<br />
# or &quot;+process Folder\Path\*.htm&quot;.<br />
#<br />
#+process jsl-test.js</div></div>
</p>
<p>
Now, Action! Let&#8217;s say I just hacked together this object literal (which, I just did&#8230;) and saved it, seems OK, no errors reported:<br />
<div id="attachment_164" class="wp-caption aligncenter" style="width: 536px"><img src="http://robrobbins.info/wp-content/uploads/2009/11/ss2.png" alt="Not triggering the .js lint error messages" title="No Errors" width="526" height="838" class="size-full wp-image-164" /><p class="wp-caption-text">Not triggering the .js lint error messages</p></div><br />
Now, what if I had <i>forgot to put a semicolon after the loadMap() function call in the objects init:</i> and then saved?<br />
<div id="attachment_166" class="wp-caption aligncenter" style="width: 536px"><img src="http://robrobbins.info/wp-content/uploads/2009/11/ss3.png" alt="Error warning triggered" title="Oops, forgot the ;" width="526" height="838" class="size-full wp-image-166" /><p class="wp-caption-text">Error warning triggered</p></div><br />
The &#8216;quickfix&#8217; window opens with the error highlighted. The line number here seems to be incorrect as line 23 is where the closing brace is, the actual missing semicolon should be on line 21. This is, however, the first run and may be a matter of configuration. Still a great start I think</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=153&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=153&amp;title=Integrating+JavaScriptLint+With+Vim+On+Windows" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=153&amp;title=Integrating+JavaScriptLint+With+Vim+On+Windows" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=153&amp;title=Integrating+JavaScriptLint+With+Vim+On+Windows&amp;desc=%0D%0AI%20use%20Vim%20to%20code%20JavaScript%20on%20my%20work%20machine%2C%20a%20PC%20running%20WinXp.%20Looking%20around%20for%20a%20way%20to%20integrate%20a%20good%20lint%20program%20to%20catch%20typical%20.js%20errors%20I%20found%20JavaScriptLint.vim.%20The%20instructions%20there%20are%20simple%2C%20drop%20the%20script%20in%20your%20vim%2Fplugins%20folder%20after%20the%20jsl.exe%20program%20has%20been%20in" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=153&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=153&amp;bm_description=Integrating+JavaScriptLint+With+Vim+On+Windows&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=153&amp;title=Integrating+JavaScriptLint+With+Vim+On+Windows" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=153&amp;title=Integrating+JavaScriptLint+With+Vim+On+Windows" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=153&amp;title=Integrating+JavaScriptLint+With+Vim+On+Windows" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=153" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Integrating+JavaScriptLint+With+Vim+On+Windows+-+http://b2l.me/cu2gq&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=153&amp;t=Integrating+JavaScriptLint+With+Vim+On+Windows" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=153</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QueryString Manipulation With The X JavaScript Library</title>
		<link>http://robrobbins.info/?p=143</link>
		<comments>http://robrobbins.info/?p=143#comments</comments>
		<pubDate>Mon, 02 Nov 2009 20:21:20 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[X]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=143</guid>
		<description><![CDATA[I&#8217;ve spent a couple of days lately coding against the Microsoft Bing maps api at work. I just put together a little method this morning to mimic .Net&#8217;s &#8216;Request.Querystring&#8217; functionality because I am needing to grab either a zip code or a latitude/longitude from the URL. The function, named requestQueryString(), expects a string to be ]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent a couple of days lately coding against the Microsoft Bing maps api at work. I just put together a little method this morning to mimic .Net&#8217;s &#8216;Request.Querystring&#8217; functionality because I am needing to grab either a zip code or a latitude/longitude from the URL. The function, named requestQueryString(), expects a string to be passed in which should be a &#8216;key&#8217; part in one of the key:value pairs located in the url of the page being viewed. In other words, if the URL is</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">www.apage.aspx?zip=85226&amp;lat=33.372154&amp;lon=-111.754322</div></div>
<p>the &#8216;keys&#8217; are &#8216;zip&#8217;, &#8216;lat&#8217; and &#8216;lon&#8217;, while the values are &#8217;85226&#8242;, &#8217;33.372154&#8242; and &#8216;-111.754322&#8242;. To fetch the value associated with zip you would do:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> zipcode <span style="color: #339933;">=</span> X.<span style="color: #660066;">requestQueryString</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'zip'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>This will return &#8217;85226&#8242; given the previous URL. For &#8216;lat&#8217; or &#8216;lon&#8217; it would be pretty much the same:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> latitude <span style="color: #339933;">=</span> X.<span style="color: #660066;">requestQueryString</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
longitude <span style="color: #339933;">=</span> X.<span style="color: #660066;">requestQueryString</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'lat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Here is the method itself. I&#8217;ll update the x.js page with the new code as well.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">requestQueryString</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//get the whole qs minus the ?</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> qs <span style="color: #339933;">=</span> window.<span style="color: #660066;">location</span>.<span style="color: #660066;">search</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//split at the '&amp;'</span><br />
&nbsp; &nbsp; splitArr <span style="color: #339933;">=</span> qs.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//to hold what we really want</span><br />
&nbsp; &nbsp; keys <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; values <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//the key passed in to get the value for</span><br />
&nbsp; &nbsp; patt <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(^| )&quot;</span> <span style="color: #339933;">+</span> key <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;( |$)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//remove any whitespace TODO do a bool to see if the qs has any %20's</span><br />
&nbsp; &nbsp; <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> splitArr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> trimArr <span style="color: #339933;">=</span> splitArr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//dont want the '%20s'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; splitArr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> trimArr<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//split the arr into key &amp; value arrays</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> splitArr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; keys<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> splitArr<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>splitArr<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; values<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> splitArr<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span>splitArr<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//look for a match for passed in key, if so...</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> k <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> keys.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//if key is matched, return its value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>patt.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>keys<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> values<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
</p>
<p>
It&#8217;s an early implementation and a couple of things are worth noting. I had an issue with whitespace because I get the lat/lon numbers from a webservice maintained elsewhere in my company, and elsewhere is not properly constraining the input. You could remove this:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><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> splitArr.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> trimArr <span style="color: #339933;">=</span> splitArr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">//dont want the '%20s'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; splitArr<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> trimArr<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>if you know that whitespace will not be an issue. Leaving it in place doesn&#8217;t add much of any overhead as the split command will just do nothing as it won&#8217;t see any &#8216;%&#8217;.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=143&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=143&amp;title=QueryString+Manipulation+With+The+X+JavaScript+Library" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=143&amp;title=QueryString+Manipulation+With+The+X+JavaScript+Library" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=143&amp;title=QueryString+Manipulation+With+The+X+JavaScript+Library&amp;desc=I%27ve%20spent%20a%20couple%20of%20days%20lately%20coding%20against%20the%20Microsoft%20Bing%20maps%20api%20at%20work.%20I%20just%20put%20together%20a%20little%20method%20this%20morning%20to%20mimic%20.Net%27s%20%27Request.Querystring%27%20functionality%20because%20I%20am%20needing%20to%20grab%20either%20a%20zip%20code%20or%20a%20latitude%2Flongitude%20from%20the%20URL.%20The%20function%2C%20named%20request" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=143&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=143&amp;bm_description=QueryString+Manipulation+With+The+X+JavaScript+Library&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=143&amp;title=QueryString+Manipulation+With+The+X+JavaScript+Library" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=143&amp;title=QueryString+Manipulation+With+The+X+JavaScript+Library" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=143&amp;title=QueryString+Manipulation+With+The+X+JavaScript+Library" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=143" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=QueryString+Manipulation+With+The+X+JavaScript+Library+-+http://b2l.me/cu2gr&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=143&amp;t=QueryString+Manipulation+With+The+X+JavaScript+Library" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=143</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>X: Pt4. Object Literals, Convenience Methods, And Go!</title>
		<link>http://robrobbins.info/?p=77</link>
		<comments>http://robrobbins.info/?p=77#comments</comments>
		<pubDate>Sat, 24 Oct 2009 20:16:06 +0000</pubDate>
		<dc:creator>rob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[X]]></category>

		<guid isPermaLink="false">http://robrobbins.info/?p=77</guid>
		<description><![CDATA[Now that we have a shiny new object created called &#8216;X&#8217;, Let&#8217;s use it. I like to organize all of my JavaScripts by incorporating object literals (see Rebecca Murphey&#8217;s talk on the closely related object lateral [that's a joke btw, it was a misprint at jconf], the excellent book Simply Javascript, and of course The ]]></description>
			<content:encoded><![CDATA[<p>Now that we have a shiny new object created called &#8216;X&#8217;, Let&#8217;s use it. I like to organize all of my JavaScripts by incorporating object literals <i>(see Rebecca Murphey&#8217;s talk on the closely related <a href="http://blog.rebeccamurphey.com/organize-your-jquery/">object lateral</a> [that's a joke btw, it was a misprint at jconf], the excellent book <a href="http://www.sitepoint.com/books/javascript1/">Simply Javascript</a>, and of course <a href="http://oreilly.com/catalog/9780596517748">The Good Parts</a> )</i>. Here&#8217;s a &#8216;stub&#8217; for the objects we could use:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> ObjectName <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; cache<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; config<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; init<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: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; otherThing<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: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>I will typically use the ObjectName.cache{} to hold a snapshot of the page, or areas of the page that I don&#8217;t want to have to re-query the DOM for. If my page is not going to change via AJAX I can store fetched results there for further use/manipulation. The ObjectName.config{} has the same functionality as .cache{}, it&#8217;s just my way of seperating out more important info than the generic .cache{}. You could use one, both, or neither, really just a matter of taste.
</p>
<p>For this to be of use we need a way to load it once the dom is ready. Let&#8217;s add a &#8216;ready&#8217; type event to the X library then:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.<span style="color: #660066;">go</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; X.<span style="color: #660066;">addEventHandler</span><span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;load&quot;</span><span style="color: #339933;">,</span>obj.<span style="color: #660066;">init</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>You&#8217;ll pass your object literal to the .go() method which will, after the page has loaded, call the init() method of the object you passed to it:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; X.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span>ObjectName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Where this goes depends on how you are constructing your site. For now, we&#8217;ll put this line just below each object literal created. Later we&#8217;ll look at a site-wide answer to automating the loading of scripts, see <a href="http://paulirish.com/2008/automate-firing-of-onload-events/">Paul Irish&#8217;s</a> blogs for more on that&#8230; </p>
<p>With a way to bind event handlers, object literals to hold the handlers, and a method to load the scripts, now we can just write some really basic JavaScript to utilize this stuff. So maybe there&#8217;s a button that lives on a page:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'x.js'</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text/javascript'</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">head</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'button'</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'say-hi'</span>&gt;</span>Click Me<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!--your external .js file linked to this page--&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;objectName.js&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">html</span></a>&gt;</span></div></div>
<p>We need to set an event handler on that button to fire when the user clicks it. In the init() function of  objectName do something like:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">init<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><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> button <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#say-hi&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; X.<span style="color: #660066;">addEventHandler</span><span style="color: #009900;">&#40;</span>button<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> ObjectName.<span style="color: #660066;">doClick</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>I&#8217;ll get to the &#8216;doClick&#8217; function in a moment. First, I want to write myself a convenience method to shorten the verbosity of adding event handlers. This is optional, of course.</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; X.$click <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> handler<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; X.<span style="color: #660066;">addEventHandler</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Now, with the convenience method added to the X library we can revisit what we wrote earlier:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> button <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#say-hi'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
X.$click<span style="color: #009900;">&#40;</span>button<span style="color: #339933;">,</span> objectName.<span style="color: #660066;">doClick</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>That&#8217;s getting better, but we can combine those 2 statements down to:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">X.$click<span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#say-hi&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> objectName.<span style="color: #660066;">doClick</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>I am using a &#8216;$&#8217; as a sigil in front of the name of the convenience methods throughout &#8216;X&#8217;. I do this to keep any conflicts with keywords like &#8216;submit&#8217;, &#8216;blur&#8217; or &#8216;focus&#8217; from happening. Plus all the cool kids are using $&#8230;
</p>
<p>
OK, so about the doClick handler. Remember that  X.addEventHandler takes a target element, an event, and a function to call when that event happens on that element. The doClick function call is in object literal notation here, it is an attribute of the object you have made. I&#8217;ve been using ObjectName as the object so far <i>(the observant among you may have noticed that the file is objectName.js. I do this in the development phase of a project as I will usually have many separate objects, all of them their own individual .js files. So objectName.js will have one object defined in it, ObjectName. At deploy time, I&#8217;ll combine them into one .js file and minify it)</i>. ObjectName will have this named function as an attribute:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">doClick<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hi!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>The event handler calls ObjectName.doClick() because you bound it to that element. Here&#8217;s the whole object then:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> ObjectName <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; init<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; X.$click<span style="color: #009900;">&#40;</span>X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#say-hi&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> objectName.<span style="color: #660066;">doClick</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
<br />
&nbsp; &nbsp; doClick<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hi!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
X.<span style="color: #660066;">go</span><span style="color: #009900;">&#40;</span>ObjectName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Don&#8217;t forget to include the call to the go() method, <i>outside of the variable</i> which passes in ObjectName and tells the browser to call ObjectName&#8217;s init() method when the DOM fires the &#8216;load&#8217; event. The cool thing about an object like this is re-usability. If your site was littered with buttons which needed to say &#8220;Hi&#8221; when pressed (<i>it could happen</i>) you would only need to attach this object to a master page and it would attach the event to any button with an id of &#8220;say-hi&#8221;. Now, it is an <b>id</b> so there should only be one per page. If there are going to be multiple instances per page, use a class instead, and iterate over the nodelist that get returns with a for loop to attach events. Assuming there are multiple buttons on the page with a <b>class=&#8221;say-hi&#8221;</b> attribute you would do:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> ObjectName <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; config<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; say<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Hi!&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
<br />
&nbsp; &nbsp; init<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><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> buttons <span style="color: #339933;">=</span> X.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.say-hi&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <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> &nbsp;i <span style="color: #339933;">&gt;</span> buttons.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; X.$click<span style="color: #009900;">&#40;</span>buttons<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> ObjectName.<span style="color: #660066;">doClick</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
<br />
&nbsp; &nbsp; doClick<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>ObjectName.<span style="color: #660066;">config</span>.<span style="color: #660066;">say</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>with this you wouldn&#8217;t have to worry about the number of elements with a class of &#8220;say-hi&#8221;, as all of them would be fitted with a click event handler that will call ObjectName.doClick(). Note the use of the config object which is an attribute of ObjectName. You can manipulate this attribute if you wanted, changing it during the page lifecycle, like say adding a toggle-type command in the doClick() function:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">doClick<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>ObjectName.<span style="color: #660066;">config</span>.<span style="color: #660066;">say</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ObjectName.<span style="color: #660066;">config</span>.<span style="color: #660066;">say</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;Hi!&quot;</span> <span style="color: #339933;">?</span> ObjectName.<span style="color: #660066;">config</span>.<span style="color: #660066;">say</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hi Again!&quot;</span> <span style="color: #339933;">:</span> ObjectName.<span style="color: #660066;">config</span>.<span style="color: #660066;">say</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hi!&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>Now the alert will alternate between &#8220;Hi!&#8221; and &#8220;Hi Again!&#8221;. Silly, but you get the idea.
</p>
<p>
Next, we&#8217;ll do a continuation of the object literal using more of the config and cache functionality, I need to get away from this keyboard now!</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-center shr-bookmarks-bg-knowledge">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://robrobbins.info/?p=77&amp;feed=comments-rss2" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://robrobbins.info/?p=77&amp;title=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://robrobbins.info/?p=77&amp;title=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://robrobbins.info/?p=77&amp;title=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21&amp;desc=Now%20that%20we%20have%20a%20shiny%20new%20object%20created%20called%20%27X%27%2C%20Let%27s%20use%20it.%20I%20like%20to%20organize%20all%20of%20my%20JavaScripts%20by%20incorporating%20object%20literals%20%28see%20Rebecca%20Murphey%27s%20talk%20on%20the%20closely%20related%20object%20lateral%20%5Bthat%27s%20a%20joke%20btw%2C%20it%20was%20a%20misprint%20at%20jconf%5D%2C%20the%20excellent%20book%20Simply%20Javascript%2C%20and" rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://robrobbins.info/?p=77&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-misterwong">
			<a href="http://www.mister-wong.com/addurl/?bm_url=http://robrobbins.info/?p=77&amp;bm_description=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21&amp;plugin=sexybookmarks" rel="nofollow" class="external" title="Add this to Mister Wong">Add this to Mister Wong</a>
		</li>
		<li class="shr-mixx">
			<a href="http://www.mixx.com/submit?page_url=http://robrobbins.info/?p=77&amp;title=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21" rel="nofollow" class="external" title="Share this on Mixx">Share this on Mixx</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://robrobbins.info/?p=77&amp;title=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://robrobbins.info/?p=77&amp;title=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://robrobbins.info/?p=77" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21+-+http://b2l.me/cu2gs&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://robrobbins.info/?p=77&amp;t=X%3A+Pt4.+Object+Literals%2C+Convenience+Methods%2C+And+Go%21" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://robrobbins.info/?feed=rss2&amp;p=77</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
