<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Reign Drops Fall...</title>
	
	<link>http://www.reigndropsfall.net</link>
	<description>Ramblings from a hacker in Iowa</description>
	<lastBuildDate>Thu, 12 Aug 2010 17:24:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/reigndropsfall" /><feedburner:info uri="reigndropsfall" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><item>
		<title>Adding Axis Titles to DojoX Charts</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/BB59bFAzgWU/</link>
		<comments>http://www.reigndropsfall.net/2010/08/12/dojox-charting-axis-titles/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 17:16:32 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[dojox]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=9191</guid>
		<description><![CDATA[DojoX charting is a very powerful 2D graphics charting solution that works cross-browser. One thing that is an often requested feature is axis titles. I&#8217;ve come up with a solution (inspired by a post on the old Dojo forums) that leverages the current API and renders correctly in all browsers. I&#8217;ll be using Dojo 1.5 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dojotoolkit.org/reference-guide/dojox/charting.html">DojoX charting</a> is a very powerful 2D graphics charting solution that works cross-browser.  One thing that is an often requested feature is axis titles.  I&#8217;ve come up with a solution (inspired by a <a href="http://o.dojotoolkit.org/forum/dojo-foundation/general-discussion/how-add-name-axes-im-not-able">post on the old Dojo forums</a>) that leverages the current API and renders correctly in all browsers.  I&#8217;ll be using Dojo 1.5 from <a href="http://code.google.com/apis/libraries/devguide.html#dojo">Google&#8217;s CDN</a> plus a local module as I outlined in my <a href="http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/">local module with a CDN build tutorial</a>.</p>
<h4>my/Chart2D.js</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">provide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.Chart2D&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dojo.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dojox.charting.Chart2D&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dojo.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.Chart2D&quot;</span><span style="color: #339933;">,</span> dojox.<span style="color: #660066;">charting</span>.<span style="color: #660066;">Chart2D</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
	render<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">inherited</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> axes <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">axes</span><span style="color: #339933;">,</span>
			theme_tick <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">theme</span>.<span style="color: #660066;">axis</span>.<span style="color: #660066;">tick</span><span style="color: #339933;">,</span>
			theme_font <span style="color: #339933;">=</span> theme_tick.<span style="color: #660066;">font</span><span style="color: #339933;">,</span>
			theme_font_color <span style="color: #339933;">=</span> theme_tick.<span style="color: #660066;">fontColor</span><span style="color: #339933;">,</span>
			dim <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dim</span><span style="color: #339933;">,</span>
			offsets <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">offsets</span><span style="color: #339933;">,</span>
			x_middle <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>dim.<span style="color: #660066;">width</span> <span style="color: #009966; font-style: italic;">/ 2) + (offsets.l /</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			y_middle <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>dim.<span style="color: #660066;">height</span> <span style="color: #009966; font-style: italic;">/ 2) - (offsets.b /</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			m <span style="color: #339933;">=</span> dojox.<span style="color: #660066;">gfx</span>.<span style="color: #660066;">matrix</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// For each axis defined, loop through, check if there</span>
		<span style="color: #006600; font-style: italic;">// is a 'title' property defined.</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">in</span> axes<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> axis <span style="color: #339933;">=</span> axes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>axis.<span style="color: #660066;">opt</span>.<span style="color: #660066;">title</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">,</span> y<span style="color: #339933;">,</span>
					rotate <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// If the axis is vertical, rotate it</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>axis.<span style="color: #660066;">vertical</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					rotate <span style="color: #339933;">=</span> <span style="color: #CC0000;">270</span><span style="color: #339933;">;</span>
					y <span style="color: #339933;">=</span> y_middle<span style="color: #339933;">;</span>
					x <span style="color: #339933;">=</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
					x <span style="color: #339933;">=</span> x_middle<span style="color: #339933;">;</span>
					y <span style="color: #339933;">=</span> dim.<span style="color: #660066;">height</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Render the text in the middle of the chart</span>
				<span style="color: #003366; font-weight: bold;">var</span> elem <span style="color: #339933;">=</span> axis.<span style="color: #660066;">group</span>.<span style="color: #660066;">createText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
					x<span style="color: #339933;">:</span> x_middle<span style="color: #339933;">,</span>
					y<span style="color: #339933;">:</span> y_middle<span style="color: #339933;">,</span>
					text<span style="color: #339933;">:</span> axis.<span style="color: #660066;">opt</span>.<span style="color: #660066;">title</span><span style="color: #339933;">,</span>
					align<span style="color: #339933;">:</span> <span style="color: #3366CC;">'middle'</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Set the font and font color</span>
				elem.<span style="color: #660066;">setFont</span><span style="color: #009900;">&#40;</span>
					axis.<span style="color: #660066;">opt</span>.<span style="color: #660066;">font</span> <span style="color: #339933;">||</span> theme_font
				<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setFill</span><span style="color: #009900;">&#40;</span>
					axis.<span style="color: #660066;">opt</span>.<span style="color: #660066;">fontColor</span> <span style="color: #339933;">||</span> theme_font_color
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// If the axis is vertical, rotate and move into position,</span>
				<span style="color: #006600; font-style: italic;">// otherwise just move into position.</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rotate<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					elem.<span style="color: #660066;">setTransform</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>
						m.<span style="color: #660066;">rotategAt</span><span style="color: #009900;">&#40;</span>rotate<span style="color: #339933;">,</span> x_middle<span style="color: #339933;">,</span> y_middle<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
						m.<span style="color: #660066;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> x <span style="color: #339933;">-</span> x_middle<span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
					elem.<span style="color: #660066;">setTransform</span><span style="color: #009900;">&#40;</span>m.<span style="color: #660066;">translate</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> y <span style="color: #339933;">-</span> y_middle<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is pretty straight-forward: the code figures out where the middle of the axes are and places the title there, rotating if necessary.  I&#8217;ll point out one important part: the text must initially be created in the middle of the chart and then translated into position.  If the text is created where it should be placed, WebKit-based browsers will hide the vertical axis&#8217; title because it initially renders partially off-screen.</p>
<p>You use this new class exactly like you would use <a href="http://dojotoolkit.org/api/dojox/charting/Chart2D.html">dojox.charting.Chart2D</a>, except that each axis can now be passed a <code>title</code> attribute:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> my.<span style="color: #660066;">Chart2D</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'chartNode'</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">setTheme</span><span style="color: #009900;">&#40;</span>dojox.<span style="color: #660066;">charting</span>.<span style="color: #660066;">themes</span>.<span style="color: #660066;">PlotKit</span>.<span style="color: #660066;">cyan</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">addPlot</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;default&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
		type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Default&quot;</span><span style="color: #339933;">,</span>
		lines<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		markers<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		tension<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">addAxis</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;x&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
		title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'X Axis'</span><span style="color: #339933;">,</span>
		min<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
		max<span style="color: #339933;">:</span> <span style="color: #CC0000;">6</span><span style="color: #339933;">,</span>
		majorTick<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> stroke<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;black&quot;</span><span style="color: #339933;">,</span> length<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		minorTick<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> stroke<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;gray&quot;</span><span style="color: #339933;">,</span> length<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">addAxis</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;y&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
		title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Y Axis'</span><span style="color: #339933;">,</span>
		vertical<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		min<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
		max<span style="color: #339933;">:</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span>
		majorTick<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> stroke<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;black&quot;</span><span style="color: #339933;">,</span> length<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		minorTick<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> stroke<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;gray&quot;</span><span style="color: #339933;">,</span> length<span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">addSeries</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Series A&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.5</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">1.5</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">1.5</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">9</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.3</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">addSeries</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Series B&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">0.3</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">6</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#123;</span> x<span style="color: #339933;">:</span> <span style="color: #CC0000;">5.5</span><span style="color: #339933;">,</span> y<span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.
	<span style="color: #660066;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://www.reigndropsfall.net/demos/charting_titles/charting_titles.html"><img src="http://www.reigndropsfall.net/wp-content/uploads/2010/08/chart-with-axis-titles.jpg" alt="Chart with axis titles" title="Chart with axis titles" class="alignnone size-medium wp-image-11238" /></a></p>
<p>I&#8217;ve posted a <a href="http://www.reigndropsfall.net/demos/charting_titles/charting_titles.html">live example</a>, a <a href="http://www.reigndropsfall.net/demos/charting_titles.tar.bz2">tarball</a>, and a <a href="http://www.reigndropsfall.net/demos/charting_titles.zip">zip file</a> for download.  As you can see, DojoX charting is quite powerful on its own but is easily extensible.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/" title="Using Local Modules With a Cross-Domain Dojo Build">Using Local Modules With a Cross-Domain Dojo Build</a></li><li><a href="http://www.reigndropsfall.net/2010/06/15/monkey-patching/" title="Monkey patching">Monkey patching</a></li><li><a href="http://www.reigndropsfall.net/2006/10/16/165/" title="Update on life">Update on life</a></li><li><a href="http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/" title="And life keeps flying by">And life keeps flying by</a></li><li><a href="http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/" title="My current endeavors">My current endeavors</a></li><li><a href="http://www.reigndropsfall.net/2006/01/21/updates-2/" title="Updates">Updates</a></li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/BB59bFAzgWU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/08/12/dojox-charting-axis-titles/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2010/08/12/dojox-charting-axis-titles/</feedburner:origLink></item>
		<item>
		<title>Using Local Modules With a Cross-Domain Dojo Build</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/Fy0_VMVA8aE/</link>
		<comments>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 18:58:30 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[xdomain]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=1941</guid>
		<description><![CDATA[Lately, I have been using Dojo from a CDN as much as possible. There are several reasons to use a cross-domain build of Dojo that are listed here: You get more connections in MSIE, since you can load from another domain. Faster loading. You get increased cacheability/startup if many of your applications use the same [...]]]></description>
			<content:encoded><![CDATA[<p>Lately, I have been using <a href="http://dojotoolkit.org">Dojo</a> from a <abbr title="Content Delivery Network"><a href="http://en.wikipedia.org/wiki/Content_Delivery_Network">CDN</a></abbr> as much as possible.  There are several reasons to use a cross-domain build of Dojo that are listed <a href="http://docs.dojocampus.org/quickstart/cross-domain">here</a>:</p>
<ol>
<li>You get more connections in MSIE, since you can load from another domain. Faster loading.</li>
<li>You get increased cacheability/startup if many of your applications use the same installation.</li>
<li>Resource loading does not block the rest of the page from filling in as with Dojo&#8217;s normal, synchronous loading.</li>
<li>With a local install, your ISP may otherwise charge you for all of those Dojo bits that you are serving.</li>
</ol>
<p>The one problem with using a CDN is that you don&#8217;t have control over the build, which means you can&#8217;t build custom code into it.  Building custom code into a build is what most people do with builds, so it would seem you can&#8217;t develop code using Dojo&#8217;s module system against a CDN.  This couldn&#8217;t be farther from the truth.</p>
<p>In this post, we&#8217;re going to be using Dojo from <a href="http://dev.aol.com/dojo">AOL&#8217;s CDN</a>.  This method can also be used against a custom cross-domain build.  It may not seem like that would be very useful, but you may need to develop a new custom module against your build and don&#8217;t want to rebuild to test each change you make.  Let&#8217;s look at the source:</p>
<h4>xdlocal.html</h4>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE HTML&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>XDomain Build With Local Modules<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
		@import &quot;http://o.aolcdn.com/dojo/1.4.3/dijit/themes/tundra/tundra.css&quot;;
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
		var djConfig = {
			isDebug: true,
			parseOnLoad: true,
			baseUrl: './',
			modulePaths: {
				'my': 'my'
			}
		};
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://o.aolcdn.com/dojo/1.4.3/dojo/dojo.xd.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
		dojo.require(&quot;my.Foo&quot;);
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tundra&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span> dojoType<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;my.Foo&quot;</span>&gt;</span>
		This is a &quot;my.Foo&quot; button.
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<h4>my/Foo.js</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">dojo.<span style="color: #660066;">provide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.Foo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dojo.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dijit.form.Button&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
dojo.<span style="color: #660066;">declare</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;my.Foo&quot;</span><span style="color: #339933;">,</span> dijit.<span style="color: #660066;">form</span>.<span style="color: #660066;">Button</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
	onClick<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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Button clicked!!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I have also provided a <a href="http://www.reigndropsfall.net/demos/xdlocal/xdlocal.html">live example</a> as well to show it working.  You can grab the source files in a <a href="http://www.reigndropsfall.net/demos/xdlocal.tar.bz2">tarball</a> or <a href="http://www.reigndropsfall.net/demos/xdlocal.zip">zip file</a> as well so you can play around with it.</p>
<p>The key part here is in the HTML file:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
	var djConfig = {
		isDebug: true,
		parseOnLoad: true,
		baseUrl: './',
		modulePaths: {
			'my': 'my'
		}
	};
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://o.aolcdn.com/dojo/1.4.3/dojo/dojo.xd.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></div></div>

<p><code>djConfig</code> is used to configure Dojo upon loading.  The <code>modulePaths</code> object tells where to find the modules relative to <code>baseUrl</code>.  Changing <code>baseUrl</code> does not affect the URL used for <code>dojo</code>, <code>dijit</code>, or <code>dojox</code> because those are hard-coded in the cross-domain build.  The main thing to remember is that <code>baseUrl</code> must end in a <code>/</code>.  Given this information, we can deduce that I am telling Dojo that the <code>my</code> modules can be found at <code>http://www.reigndropsfall.net/demos/xdlocal/my/</code>.</p>
<p>As you can see from this simple example, Dojo&#8217;s module system is very versatile.  Not only can you host a build, host a custom build, host a cross-domain build, or use a CDN, but you can combine cross-domain builds with local modules which can save time and bandwidth costs.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.reigndropsfall.net/2010/08/12/dojox-charting-axis-titles/" title="Adding Axis Titles to DojoX Charts">Adding Axis Titles to DojoX Charts</a></li><li><a href="http://www.reigndropsfall.net/2010/06/15/monkey-patching/" title="Monkey patching">Monkey patching</a></li><li><a href="http://www.reigndropsfall.net/2006/10/16/165/" title="Update on life">Update on life</a></li><li><a href="http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/" title="And life keeps flying by">And life keeps flying by</a></li><li><a href="http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/" title="My current endeavors">My current endeavors</a></li><li><a href="http://www.reigndropsfall.net/2006/01/21/updates-2/" title="Updates">Updates</a></li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/Fy0_VMVA8aE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/</feedburner:origLink></item>
		<item>
		<title>Monkey patching</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/8pyX7sKftjE/</link>
		<comments>http://www.reigndropsfall.net/2010/06/15/monkey-patching/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 21:28:38 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=889</guid>
		<description><![CDATA[Recently, David Walsh tweeted that I had schooled him. I received several questions about what I had schooled him in, so I decided to blog about it. David was trying to change the behavior of a method of a widget on a page, but for all instances of that widget rather than just one instance. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, <a href="http://davidwalsh.name/">David Walsh</a> <a href="http://twitter.com/davidwalshblog/status/16173861841">tweeted</a> that I had schooled him.  I received several questions about what I had schooled him in, so I decided to blog about it.</p>
<p>David was trying to change the behavior of a method of a widget on a page, but for all instances of that widget rather than just one instance.  What follows is a lesson on monkey patching.  I&#8217;m sure there are other tutorials out there about it, but this is more for my sanity (and to get David off my back about blogging) than anything else.</p>
<p>Wikipedia defines <a href="http://en.wikipedia.org/wiki/Monkey_patch">Monkey patching</a> as &#8220;a way to extend or modify the runtime code of dynamic languages (e.g. Smalltalk, JavaScript, Objective-C, Ruby, Perl, Python, Groovy, etc.) without altering the original source code.&#8221;  For our purposes, we&#8217;ll only be looking at JavaScript.  Wikipedia also lists four uses for monkey patching:</p>
<ul>
<li>Replace methods/attributes/functions at runtime.</li>
<li>Modify/extend behavior of a third-party product without maintaining a private copy of the source code.</li>
<li>Apply a patch at runtime to the objects in memory, instead of the source code on disk.</li>
<li>Distribute security or behavioral fixes that live alongside the original source code.</li>
</ul>
<p>In the JavaScript world, monkey patching can be very important if you&#8217;re using a third-party library.  This is especially true if you are using it from a <abbr title="Content Delivery Network"><a href="http://en.wikipedia.org/wiki/Content_delivery_network">CDN</a></abbr> or are checking it out from a version control system.  We&#8217;ll use this HTML as our test page and use <a href="http://dojotoolkit.org">Dojo</a> from the <a href="http://dev.aol.com/dojo">AOL CDN</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt; !DOCTYPE HTML&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>A Monkey-patching example<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://o.aolcdn.com/dojo/1.4.3/dojo/dojo.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
		dojo.ready(function(){
			dojo.declare(&quot;Adder&quot;, null, {
				constructor: function(base){
					this._base = base;
				},
&nbsp;
				add: function(what){
					return this._base + what;
				}
			});
		});
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>I will assume basic knowledge of JavaScript, object prototype chains, and <code>dojo.declare</code>.  The code examples that follow can be pasted into your browser&#8217;s JavaScript console (such as <a href="http://getfirebug.com/">Firebug</a>).</p>
<h3>Monkey patching object instances</h3>
<p>Let&#8217;s say you have an <code>Adder</code> instance and you&#8217;d like to change the calculation that happens when calling <code>add()</code>.  Simply add an <code>add</code> method to the object instance:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myAdder <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Adder<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myAdder.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 10</span>
myAdder.<span style="color: #660066;">add</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>what<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> what <span style="color: #339933;">+</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
myAdder.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 25</span></pre></div></div>

<p>That&#8217;s all well and good, but how do we perform the original <code>add</code> calculation, yet modify it without rewriting the method completely?  Just store the <code>add</code> method to a variable, add an <code>add</code> method to the object instance, and call the stored <code>add</code> method within the new <code>add</code> method.  You&#8217;ll generally also want to wrap that all in a closure so only the new method can access the old method.  Confused yet?  Don&#8217;t be:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myAdder2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Adder<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myAdder2.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 10</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> oldAdd <span style="color: #339933;">=</span> myAdder2.<span style="color: #660066;">add</span><span style="color: #339933;">;</span>
	myAdder2.<span style="color: #660066;">add</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>what<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> oldAdd.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> what<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myAdder2.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 30</span></pre></div></div>

<h3>One note</h3>
<p>You might have noticed that I didn&#8217;t use the word &#8220;overwrite&#8221; when talking about monkey patching object instances.  This is because object instances look up their properties from their prototype unless explicitly defined on them (like <code>_base</code>).  This is what one might call &#8220;masking&#8221; and is an important concept in JavaScript.  When we were monkey patching before, we were actually masking the <code>add</code> method on the <code>Adder</code> prototype (it&#8217;s a subtle difference, but important).</p>
<h3>Monkey patching an object&#8217;s prototype</h3>
<p>Great!  We can modify individual instances.  But let&#8217;s say we have 30 Adder instances and we don&#8217;t want to modify them all every time.  This is where monkey patching the prototype comes in:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myAdder3 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Adder<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myAdder3.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 10</span>
Adder.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">add</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>what<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>._base <span style="color: #339933;">+</span> what <span style="color: #339933;">+</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
myAdder3.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 20</span></pre></div></div>

<p>Here, we&#8217;re overwriting (instead of masking) the <code>add</code> method.  This applies to instances already created that haven&#8217;t had their methods masked (try <code>myAdder.add(5);</code> and <code>myAdder2.add(5);</code>) and future created instances.  As we did before, you can also call the originally defined method:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myAdder4 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Adder<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myAdder4.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 20</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> oldAdd <span style="color: #339933;">=</span> Adder.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">add</span><span style="color: #339933;">;</span>
	Adder.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">add</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>what<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> oldAdd.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> what<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
myAdder4.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 30</span>
myAdder3.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns 30</span></pre></div></div>

<p>Note how <code>myAdder3</code> is also affected by this new monkey patch.  As you can see, monkey patching is quite simple yet very powerful.  Although I used <code>dojo.declare</code>, this can be used to modify any JavaScript object or prototype chain: you can modify a widget&#8217;s behavior, add debugging output to a method, or even modify arguments passed to the original function.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.reigndropsfall.net/2010/08/12/dojox-charting-axis-titles/" title="Adding Axis Titles to DojoX Charts">Adding Axis Titles to DojoX Charts</a></li><li><a href="http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/" title="Using Local Modules With a Cross-Domain Dojo Build">Using Local Modules With a Cross-Domain Dojo Build</a></li><li><a href="http://www.reigndropsfall.net/2006/10/16/165/" title="Update on life">Update on life</a></li><li><a href="http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/" title="And life keeps flying by">And life keeps flying by</a></li><li><a href="http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/" title="My current endeavors">My current endeavors</a></li><li><a href="http://www.reigndropsfall.net/2006/01/21/updates-2/" title="Updates">Updates</a></li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/8pyX7sKftjE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/06/15/monkey-patching/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2010/06/15/monkey-patching/</feedburner:origLink></item>
		<item>
		<title>Back from hiatus</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/tzZFGhgcbF0/</link>
		<comments>http://www.reigndropsfall.net/2010/06/15/back-from-hiatus/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 21:14:23 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=926</guid>
		<description><![CDATA[It&#8217;s been a long long time since I&#8217;ve seriously blogged and I&#8217;m going to get back into it again (at the behest of David Walsh). I&#8217;ve got a couple of tutorials and/or tips lined up and I intend to keep up with it. Alright, back to your regularly scheduled programming&#8230; Related PostsNo Related Post]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long long time since I&#8217;ve seriously blogged and I&#8217;m going to get back into it again (at the behest of <a href="http://davidwalsh.name/">David Walsh</a>).  I&#8217;ve got a couple of tutorials and/or tips lined up and I intend to keep up with it.  Alright, back to your regularly scheduled programming&hellip;</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/tzZFGhgcbF0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/06/15/back-from-hiatus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2010/06/15/back-from-hiatus/</feedburner:origLink></item>
		<item>
		<title>Recipe for Brye</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/6EWBmPEBdyM/</link>
		<comments>http://www.reigndropsfall.net/2009/02/24/recipe-for-brye/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 22:00:02 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[family]]></category>
		<category><![CDATA[recipe]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=465</guid>
		<description><![CDATA[A few people have asked me for this after I made mention of it in my status updates. This is a Forbes-family treat that is great when you&#8217;re feeling crummy. We used to have it all the time when I was a kid and we were home from school. I just learned the other night [...]]]></description>
			<content:encoded><![CDATA[<p>A few people have asked me for this after I made mention of it in my status updates.  This is a Forbes-family treat that is great when you&#8217;re feeling crummy.  We used to have it all the time when I was a kid and we were home from school.  I just learned the other night that it&#8217;s actually a dessert (I would never have guessed).  Anyway, here is the recipe for Brye:</p>
<blockquote><p>
Ingredients:<br />
2 cups milk<br />
1/2 cup sugar<br />
1/4 cup flour<br />
pinch of salt<br />
1 tsp vanilla<br />
1 egg<br />
2 tbsp butter</p>
<p>Directions:<br />
Put the sugar and flour into a medium saucepan.  Measure the milk in a glass measuring cup and pour into saucepan.  In the same measuring cup, whisk the egg and pour into saucepan.  Bring to a boil.  Add the butter, vanilla, and salt and stir until it thickens.  Let it cool a bit before partaking!
</p></blockquote>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/6EWBmPEBdyM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2009/02/24/recipe-for-brye/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2009/02/24/recipe-for-brye/</feedburner:origLink></item>
		<item>
		<title>A petition to take back our freedoms</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/sNqIS2DoZyw/</link>
		<comments>http://www.reigndropsfall.net/2008/07/29/a-petition-to-take-back-our-freedoms/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 23:48:50 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Politics]]></category>
		<category><![CDATA[bush administration]]></category>
		<category><![CDATA[impeachment]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=293</guid>
		<description><![CDATA[I know it&#8217;s been a long time since I&#8217;ve written a real blog post, but I wanted to make sure everyone knew about this: A petition to bring articles of impeachment against the Bush administration. If you have the time, please read the articles. For those of you who don&#8217;t like to read and would [...]]]></description>
			<content:encoded><![CDATA[<p>I know it&#8217;s been a long time since I&#8217;ve written a real blog post, but I wanted to make sure everyone knew about this: <a href="http://kucinich.us/">A petition to bring articles of impeachment against the Bush administration</a>.  If you have the time, please read <a href="http://kucinich.us/impeachment/articles.pdf">the articles</a>.  For those of you who don&#8217;t like to read and would rather watch something (or even listen to it), please check out these links:</p>
<p><a href="http://www.youtube.com/watch?v=DRAcenaTVkQ">Hearing on Limits of Executive Power: Dennis Kucinich</a><br />
<a href="http://www.youtube.com/watch?v=80IphtHrFzg">Hearing on Limits of Executive Power: Bruce Fein</a><br />
<a href="http://www.youtube.com/watch?v=GDAFozFn4kU">Hearing on Limits of Executive Power: Vincent Bugliosi</a><br />
<a href="http://www.youtube.com/watch?v=_T1ojrKhp6E">Hearing on Limits of Executive Power: Robert Wexler</a></p>
<p>I want to let everyone know that I&#8217;m not a war for oil, moveon.org, or Bush==Hitler person.  I voted for Bush in 2000 and 2004.  I supported the Bush administration&#8217;s decision to go into Afghanistan to fight Al-Qaeda.  I even bought the need to go into Iraq.  But I&#8217;m also a person who believes that if you make a mistake, you don&#8217;t cover it up: you own up.  I believe that when an someone abuses the power they have been given, they need to be held accountable.  I urge you to read the articles of impeachment and watch the clips and decide for yourself.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/sNqIS2DoZyw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2008/07/29/a-petition-to-take-back-our-freedoms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2008/07/29/a-petition-to-take-back-our-freedoms/</feedburner:origLink></item>
		<item>
		<title>If you support our troops…</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/6yomOCB2a3M/</link>
		<comments>http://www.reigndropsfall.net/2008/02/16/if-you-support-our-troops/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 17:32:58 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Politics]]></category>
		<category><![CDATA[ron paul]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2008/02/16/if-you-support-our-troops/</guid>
		<description><![CDATA[I know I&#8217;m way overdue for an update, but I had to post this. I&#8217;ve also tried to stay out of the political posting this season, but I thought I&#8217;d post this. The mainstream media has done an excellent job of squelching a fine candidate: Ron Paul. Yes, he has very libertarian stands and that&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I know I&#8217;m way overdue for an update, but I had to post this.  I&#8217;ve also tried to stay out of the political posting this season, but I thought I&#8217;d post this.  The mainstream media has done an excellent job of squelching a fine candidate: <a href="http://www.ronpaul2008.com">Ron Paul</a>.  Yes, he has very libertarian stands and that&#8217;s what appeals to me: he believes that the federal government should only take care of what is outlined in the constitution.  It seems like his message is resonating with our troops (warning: Flash content follows&#8230; I&#8217;m not a big fan of proprietary technology, but I feel like this needs to be spread):</p>
<p><object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/j5Aue2yZAOs&#038;rel=1&#038;border=0"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/j5Aue2yZAOs&#038;rel=1&#038;border=0" type="application/x-shockwave-flash" wmode="transparent"width="425" height="355"></embed></object></p>
<p>Via <a href="http://www.dailypaul.com/node/38411">Daily Paul</a>.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/6yomOCB2a3M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2008/02/16/if-you-support-our-troops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2008/02/16/if-you-support-our-troops/</feedburner:origLink></item>
		<item>
		<title>Through field and barbed wire</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/WLGn9ks_QZ0/</link>
		<comments>http://www.reigndropsfall.net/2007/06/19/through-field-and-barbed-wire/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 15:10:08 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[asaph's apprentice]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2007/06/19/through-field-and-barbed-wire/</guid>
		<description><![CDATA[So last night, Asaph&#8217;s Apprentice drove down to Lamoine Christian Service Camp last night to play a show. It wouldn&#8217;t have been too much of a hassle, except that we got our directions from MapQuest (no link love for them&#8230; you&#8217;ll soon see why). Here are the directions we used. Note directions #14 and #16. [...]]]></description>
			<content:encoded><![CDATA[<p>So last night, Asaph&#8217;s Apprentice drove down to <a href="http://www.lamoinechristiancamp.org/">Lamoine Christian Service Camp</a> last night to play a show.  It wouldn&#8217;t have been too much of a hassle, except that we got our directions from MapQuest (no link love for them&#8230; you&#8217;ll soon see why).</p>
<p><a href="http://www.mapquest.com/directions/main.adp?go=1&#038;do=nw&#038;rmm=1&#038;mo=ma&#038;2si=navt&#038;un=m&#038;1rc=L1AAA&#038;cl=EN&#038;qq=IEaKSvfsRsoEUP0r5eJRzX7qYmW%252bAyeym7GXdrX4O%252bgj%252b%252baG9zMhFepX6KMMunttEQqysXg%252bE64nwGXm0CHRbVHguVKowXl%252f3jwElyocDorOTxn3r6ip%252f7lIsk0hxXx6syHEKbikMTcOog1EHx9wLilADknB1cQIHUvd4usWbYc3j50dPVVd1KeVtN4PlgFsVwn1L075lIDnPA%252fnw%252b3DxTE8CEgbR8mj8Y%252bS6MS6mz2n448PnMWHrCQD5GLjhsgg9JUjYgT%252b2cOd5rxMbiewE57dzAZhhWMm9470K8ydHqW3Qasbpz%252b2Hw7bmu5nZkYu20tNleSzsMgXY7FloZP1%252ff9C37X5Oa%252bPj1E4LsbqeZuPY%252fqkLYnM0C8l0DbzQoW2moMdRZI9oIUgoPIqBNyO9snEbwBNtgtSQgizwZ2cGbqtKhU6Bru39Uy%252bpEA8Fe14&#038;ct=NA&#038;r=f&#038;1si=navt&#038;2rc=L1AAA&#038;did=1182262736&#038;rsres=1&#038;1y=US&#038;1ffi=&#038;1l=&#038;1g=&#038;1pl=&#038;1v=&#038;1n=&#038;1pn=&#038;1a=111+CANDLESTICK+DR+NE&#038;1c=MOUNT+VERNON&#038;1s=IA&#038;1z=52314-1541&#038;panelbtn=1&#038;2y=US&#038;2ffi=&#038;2l=5XcEO8WjHPGO3n4yGAfNnA%253d%253d&#038;2g=7fAhh3FEtJdvsQVid548Ww%253d%253d&#038;2pl=&#038;2v=ADDRESS&#038;2n=HANCOCK+COUNTY&#038;2pn=&#038;2a=2760+E+County+Road+1600&#038;2c=Tennessee&#038;2s=IL&#038;2z=62374-3005">Here</a> are the directions we used.  Note directions #14 and #16.  Right turns on CR-2800&#8230; easy enough.  Or so we thought.  The first turn onto CR-2800 goes through some guy&#8217;s field and ends up where the directions say it should.  The second turn onto CR-2800 is a little more misleading.  If you click on the map link for direction #16, it shows you a nice straight road&#8230; this is not what CR-2800 currently looks like.  We ended up driving through another field and ended <strong>at a barbed wire fence</strong>.  I wish we would have taken a picture&#8230; it was priceless.  Thank you MapQuest.</p>
<p>Of course, Google Maps doesn&#8217;t get it <a href="http://maps.google.com/maps?f=d&#038;hl=en&#038;saddr=111+Candlestick+Dr,+Mount+Vernon,+IA+52314&#038;daddr=2760+E.+County+Road+1600,+Tennessee,+IL+62374&#038;sll=41.207096,-91.320419&#038;sspn=2.979475,3.702393&#038;ie=UTF8&#038;ll=41.178654,-91.318359&#038;spn=2.980792,3.702393&#038;z=8&#038;om=1">any better</a> and Rand McNally <a href="http://www.randmcnally.com/rmc/directions/dirGetDirections.jsp?BV_SessionID=@@@@0107167583.1182264793@@@@&#038;BV_EngineID=ccceaddlffgjhhdcefecggfdffhdgnh.0&#038;cmty=0&#038;notcache=1">fails miserably</a> as well.  The only directions site that gives directions that don&#8217;t end up in the middle of nowhere (literally) is Yahoo! Maps.  And <a href="http://maps.yahoo.com/broadband#gid2=17584515&#038;q2=2760+E.+County+Road+1600%2C+Tennessee%2C+IL+62374&#038;q1=Cedar+Rapids%2C+IA%2C+52403&#038;mvt=m&#038;trf=0&#038;lon=-91.238708&#038;lat=41.294317&#038;mag=10">their directions</a> end up taking less time too.</p>
<p>What is it with these map sites?  Why don&#8217;t they have a review feature?  It ended up taking us an hour more to get to the camp because we had to backtrack out of the field (while bottoming out a couple of times) and then flagging down someone who&#8217;s first question to us was, &#8220;Are you guys looking for the camp?&#8221;  If we hadn&#8217;t have planned to get there 2 hours early, we would have been late.  And yes, I know that all of these map sites have their little disclaimer that says something to the effect of &#8220;if these directions suck and you end up in the middle of a field or lake or get eaten by cannibals it&#8217;s not our fault,&#8221; but seriously&#8230; it&#8217;d be nice to be able to get alternate routes from people that actually live in the place that you&#8217;re going to or have been there before.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/WLGn9ks_QZ0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2007/06/19/through-field-and-barbed-wire/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2007/06/19/through-field-and-barbed-wire/</feedburner:origLink></item>
		<item>
		<title>Don’t Panic!!!</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/gxlUqkbWmEs/</link>
		<comments>http://www.reigndropsfall.net/2007/05/25/dont-panic/#comments</comments>
		<pubDate>Fri, 25 May 2007 14:49:49 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[towel day]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2007/05/25/dont-panic/</guid>
		<description><![CDATA[Today is Towel Day. That is all for now. Related PostsNo Related Post]]></description>
			<content:encoded><![CDATA[<p>Today is <a href="http://en.wikipedia.org/wiki/Towel_day">Towel Day</a>.  That is all for now.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/gxlUqkbWmEs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2007/05/25/dont-panic/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2007/05/25/dont-panic/</feedburner:origLink></item>
		<item>
		<title>It’s for the little foxes</title>
		<link>http://feedproxy.google.com/~r/reigndropsfall/~3/Fw554tH3xjM/</link>
		<comments>http://www.reigndropsfall.net/2007/03/27/its-for-the-little-foxes/#comments</comments>
		<pubDate>Tue, 27 Mar 2007 19:03:05 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[firefox]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2007/03/27/its-for-the-little-foxes/</guid>
		<description><![CDATA[Brought to you by the Mozilla Developer Center: So, let&#8217;s all spread the propaganda message! Related PostsNo Related Post]]></description>
			<content:encoded><![CDATA[<p>Brought to you by the Mozilla Developer Center:</p>
<p><a href="http://developer.mozilla.org/en/docs/Promote_MDC"><img src="http://www.reigndropsfall.net/images/Moz_ffx_openStandards_264x198.jpg" alt="MDC" /></a></p>
<p>So, let&#8217;s all spread the <del>propaganda</del> message!</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li>No Related Post</li></ul><img src="http://feeds.feedburner.com/~r/reigndropsfall/~4/Fw554tH3xjM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2007/03/27/its-for-the-little-foxes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.reigndropsfall.net/2007/03/27/its-for-the-little-foxes/</feedburner:origLink></item>
	</channel>
</rss>
