<?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>Reign Drops Fall... &#187; dojo</title>
	<atom:link href="http://www.reigndropsfall.net/tag/dojo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.reigndropsfall.net</link>
	<description>Ramblings from a hacker in Iowa</description>
	<lastBuildDate>Wed, 07 Jul 2010 19:02:52 +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>Using Local Modules With a Cross-Domain Dojo Build</title>
		<link>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/</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/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>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/07/07/local-modules-with-xdomain/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Monkey patching</title>
		<link>http://www.reigndropsfall.net/2010/06/15/monkey-patching/</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/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>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2010/06/15/monkey-patching/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Update on life</title>
		<link>http://www.reigndropsfall.net/2006/10/16/165/</link>
		<comments>http://www.reigndropsfall.net/2006/10/16/165/#comments</comments>
		<pubDate>Mon, 16 Oct 2006 14:00:47 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[capoeira]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[sitepen]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2006/10/16/165/</guid>
		<description><![CDATA[Man, I keep telling myself I&#8217;ll write more often, and then I go a month or so without writing&#8230; what is my problem? Let me catch you guys up with what&#8217;s happening. Work After a year and a half at Master Packing and Rubber Company, I&#8217;m leaving my position there to join the gang over [...]]]></description>
			<content:encoded><![CDATA[<p>Man, I keep telling myself I&#8217;ll write more often, and then I go a month or so without writing&#8230; what is my problem?  Let me catch you guys up with what&#8217;s happening.</p>
<p><strong>Work</strong><br />
After a year and a half at Master Packing and Rubber Company, I&#8217;m leaving my position there to join the gang over at <a href="http://www.sitepen.com">SitePen</a> full time working on <a href="http://www.dojotoolkit.org">Dojo</a> and other DHTML/JavaScript web application &#8220;stuff&#8221;.  My last day at MPRC is this Friday and I start at SitePen a week from today.  I&#8217;ll still be working on MPRC&#8217;s website in my free time and offering them a bit of technical support every once and a while (read: over the next month, I&#8217;ll be getting phone calls left and right from them).  It&#8217;s been a fun year and a half and I&#8217;ve learned a ton about business, quality assurance, and website administration and I truly appreciate them giving me the opportunity to work for them.  That being said, I&#8217;m really looking forward to working from home for SitePen and working full time with the some of the best in DHTML and JavaScript.</p>
<p><strong>Dojo</strong><br />
We&#8217;re approaching our 0.4 release and there are plenty of treats for this release!  One of the biggest developments for this release is the gfx package.  Gfx is an SVG drawing API that works in both IE and Firefox.  Check out the <a href="http://archive.dojotoolkit.org/nightly/tests/widget/test_Clock.html">clock demo</a>.  Another SVG goodie we&#8217;re packing into this release is the <a href="http://archive.dojotoolkit.org/nightly/tests/widget/charting/engine/test_engine.html">charting engine</a>.  These goodies are thanks to the wonderful work of Eugene Lazutkin, Tom Trenka, Gavin Doherty, and Kun Xi.</p>
<p><strong>Capoeira</strong><br />
Last Wenesday, my wife took some (over 200) <a href="http://gallery.reigndropsfall.net/v/capoeira/">pictures</a> at our capoeira class of our capoeira family.  I&#8217;ve posted them here.  She started taking pictures during aÃº and handstand exercises, took them throughout the roda, and ended the excursion at <a href="http://www.thaiflavors.net">Thai Flavors</a> (our hangout after Wednesday night practice).</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.reigndropsfall.net/2007/02/25/long-overdue/" title="Long Overdue">Long Overdue</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/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/09/11/it-freaking-hurts/" title="It freaking hurts">It freaking hurts</a></li><li><a href="http://www.reigndropsfall.net/2006/06/22/capoeira/" title="Capoeira">Capoeira</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/01/21/updates-2/" title="Updates">Updates</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2006/10/16/165/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>And life keeps flying by</title>
		<link>http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/</link>
		<comments>http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/#comments</comments>
		<pubDate>Tue, 20 Jun 2006 03:03:35 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[dojo developer day]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/</guid>
		<description><![CDATA[It&#8217;s been almost a month and a half and my blogging has been quite absent. Here&#8217;s what has been happening&#8230; Life Our trip to San Jose (last month) went great. We had 4 days to bum around Silicon Valley and the surrounding areas. Since this was a vacation, we decided not to do too much [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been almost a month and a half and my blogging has been quite absent.  Here&#8217;s what has been happening&#8230;</p>
<p><span style="font-weight: bold">Life</span><br />
Our trip to San Jose (last month) went great.  We had 4 days to bum around Silicon Valley and the surrounding areas.  Since this was a vacation, we decided not to do too much and really only did one touristy thing: we went down to Carmel and 17 mile drive for a day.  It was fun and it was a really beautiful area.  And the driving out there wasn&#8217;t too bad.  The Dojo Developer Day (which is what I went out there for in the first place) went great as well.</p>
<p><span style="font-weight: bold">Dojo</span><br />
Dojo has been taking off recently.  Last month, we released 0.3.0 and about a week ago we released 0.3.1.  For the 0.3.0 release, I refactored/rewrote the effects portion, James Burke wrote a cross-domain loader, Tom Trenka added a Google and Yahoo! maps interface, and Torrey Rice added the new widget theme.  There was more, but those are the ones that stick out in my mind.  We had about 50k downloads in the month that 0.3.0 was out.  For 0.3.1, the cross-domain loading has been improved and we have a cross-domain package now, plus AOL is now hosting Dojo on their CDN, IBM is actively helping with a11y, and Sun just announced they are going to start developing widgets for Dojo.  All-in-all, it&#8217;s been a good month.</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/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>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2006/06/19/and-life-keeps-flying-by/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My current endeavors</title>
		<link>http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/</link>
		<comments>http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/#comments</comments>
		<pubDate>Sat, 01 Apr 2006 22:29:51 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[coaster]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[sitepen]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/</guid>
		<description><![CDATA[Ok, so I said I would keep up with this blogging thing, but I&#8217;m not doing a very good job. It&#8217;s been over two months since I last blogged. What the heck is my problem? So here&#8217;s the run-down of what I&#8217;ve been doing: Work I&#8217;ve been steadily plugging away at Master Packing&#8217;s web site [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so I said I would keep up with this blogging thing, but I&#8217;m not doing a very good job.  It&#8217;s been over two months since I last blogged.  What the heck is my problem?  So here&#8217;s the run-down of what I&#8217;ve been doing:</p>
<p><strong>Work</strong><br />
I&#8217;ve been steadily plugging away at Master Packing&#8217;s web site over the last two months.  I&#8217;ve been trying to implement interactive features to some fairly boring things.  Once its up, I&#8217;ll highlight what I&#8217;ve done, but until then, I&#8217;ve got to explain.  On the mechanical packing page, I&#8217;ve used the Tree widget from <a href="http://dojotoolkit.org">Dojo</a> to let you figure out which style of our mechanical packing matches other companies&#8217; packing.  Also, you can compare the temperature, pH, and speed ratings on all the mechanical packing we offer using the SortableTable widget.  On the rail and marine page, you&#8217;ll be able to search for a partial or complete EMD number and the server will show you what part number we sell that part under and also suitable replacements.  This search feature is something that isn&#8217;t available anywhere else in the EMD aftermarket industry.  We should have it up and running by mid April.  I&#8217;ll definately post when it&#8217;s up.</p>
<p><strong>JavaScript</strong><br />
For the last month, I&#8217;ve been delving deep into the world of JavaScript for SitePen.  It has taken me a while, but I think I&#8217;ve gotten the hang of the prototype-base inheritance that JavaScript uses.  I think I&#8217;m past the fact that you can extend the prototype of any class so if you want a new method or want to modify an old method, you don&#8217;t create a new class.  You just &#8220;mask&#8221; the old method on the current class.  Coming from C++, that blew my mind.</p>
<p><strong>Coaster</strong><br />
Development has pretty much stalled.  I&#8217;ve been so busy with life, music, Dojo, <a href="http://www.djangoproject.com">Django</a>, work, contracting, and everything else that I haven&#8217;t had time to sit down and code on <a href="http://www.coaster-burner.org">Coaster</a> for a long time.  Also, the success of programs like Serpentine have shown me that other people are more motivated than I am.  If someone wants to take the coding portion of the project over, contact me or Sean Harshbarger on the Coaster mailing list.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.reigndropsfall.net/2006/01/21/updates-2/" title="Updates">Updates</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/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/2007/02/25/long-overdue/" title="Long Overdue">Long Overdue</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/01/29/publicity/" title="Publicity">Publicity</a></li><li><a href="http://www.reigndropsfall.net/2005/11/09/dork-sided/" title="Dork-sided">Dork-sided</a></li><li><a href="http://www.reigndropsfall.net/2005/09/13/catching-up/" title="Catching up">Catching up</a></li><li><a href="http://www.reigndropsfall.net/2005/08/07/updates/" title="Updates">Updates</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2006/04/01/my-current-endeavors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Updates</title>
		<link>http://www.reigndropsfall.net/2006/01/21/updates-2/</link>
		<comments>http://www.reigndropsfall.net/2006/01/21/updates-2/#comments</comments>
		<pubDate>Sun, 22 Jan 2006 03:58:29 +0000</pubDate>
		<dc:creator>Bryan Forbes</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[coaster]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[dojo]]></category>

		<guid isPermaLink="false">http://www.reigndropsfall.net/?p=147</guid>
		<description><![CDATA[Man, I&#8217;ve been busy lately and haven&#8217;t had any time to work on Coaster. I haven&#8217;t even really had much time for anything other than work. Although I&#8217;ve had fun doing it, it&#8217;s been hectic. Most of my time lately has been spent working on converting Master Packing&#8217;s current website over to Django so we [...]]]></description>
			<content:encoded><![CDATA[<p>Man, I&#8217;ve been busy lately and haven&#8217;t had any time to work on <a href="http://www.coaster-burner.org">Coaster</a>.  I haven&#8217;t even really had much time for anything other than work.  Although I&#8217;ve had fun doing it, it&#8217;s been hectic.</p>
<p>Most of my time lately has been spent working on converting Master Packing&#8217;s current website over to <a href="http://www.djangoproject.com">Django</a> so we can quickly develop new applications and easily edit content.  I&#8217;ve been very impressed with Django&#8217;s infrastructure and API, and I&#8217;m even more impressed with how the next version is shaping up to look like.  They&#8217;ve changed it so that a lot of the &#8220;magic&#8221; is gone and the API is improving.  1.0 should be sweet.</p>
<p>I&#8217;ve also been working with the <a href="http://www.dojotoolkit.org">Dojo</a> javascript toolkit as well.  It&#8217;s a pretty neat toolkit that is pretty powerful.  I like how dojo.io.bind works for AJAX requests.  They also have dojo.event.connect that works kind of like glib&#8217;s event connecting.  The documentation is on the bare side (as in, not much at all), but that&#8217;s being worked on.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><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/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/01/29/publicity/" title="Publicity">Publicity</a></li><li><a href="http://www.reigndropsfall.net/2005/11/09/dork-sided/" title="Dork-sided">Dork-sided</a></li><li><a href="http://www.reigndropsfall.net/2005/09/13/catching-up/" title="Catching up">Catching up</a></li><li><a href="http://www.reigndropsfall.net/2005/08/07/updates/" title="Updates">Updates</a></li><li><a href="http://www.reigndropsfall.net/2005/07/14/oh-the-joy-of-technology/" title="Oh the joy of technology">Oh the joy of technology</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.reigndropsfall.net/2006/01/21/updates-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
