<?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>Ajaxian &#187; Closure</title>
	<atom:link href="http://ajaxian.com/by/topic/closure/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Tue, 22 May 2012 21:45:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
    	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Closure Lite</title>
		<link>http://ajaxian.com/archives/closure-lite</link>
		<comments>http://ajaxian.com/archives/closure-lite#comments</comments>
		<pubDate>Thu, 24 Dec 2009 11:39:52 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Closure]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[Google]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=8346</guid>
		<description><![CDATA[Michael Bolin formerly of Google has created Closure Lite as a way to let developers get their feet wet in the Closure library without having to go into the compiler and the like (but they should do that eventually!). Closure Lite itself consists of the following subset of APIs: goog.array goog.Disposable goog.dispose goog.dom goog.dom.DomHelper goog.events.NodeType <a href="http://ajaxian.com/archives/closure-lite">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Michael Bolin <a href="http://blog.bolinfest.com/2009/10/4-years-2-months-and-1-day.html">formerly of Google</a> has <a href="http://blog.bolinfest.com/2009/12/closure-lite-just-in-time-for-christmas.html">created Closure Lite</a> as a way to let developers get their feet wet in the Closure library without having to go into the compiler and the like (but they should do that eventually!).</p>
<p><a href="http://www.programmingclosure.com/closure-lite/">Closure Lite</a> itself consists of the following subset of APIs:</p>
<ul>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_array_array.js.html">goog.array</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_Disposable.html">goog.Disposable</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_disposable_disposable.js.html">goog.dispose</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_dom_dom.js.html">goog.dom</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_dom_DomHelper.html">goog.dom.DomHelper</a></li>
<li>goog.events.NodeType</li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_dom_tagname.js.html">goog.dom.TagName</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_dom_classes.js.html">goog.dom.classes</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_dom_xml.js.html">goog.dom.xml</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_events_events.js.html">goog.events</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_BrowserEvent.html">goog.events.BrowserEvent</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_Event.html">goog.events.Event</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_EventHandler.html">goog.events.EventHandler</a></li>
<li>goog.events.EventType</li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_EventTarget.html">goog.events.EventTarget</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_KeyEvent.html">goog.events.KeyEvent</a></li>
<li>goog.events.KeyCodes</li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_KeyHandler.html">goog.events.KeyHandler</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_events_Listener.html">goog.events.Listener</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_functions_functions.js.html">goog.functions</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_json_json.js.html">goog.json</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_math_Box.html">goog.math.Box</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_math_Coordinate.html">goog.math.Coordinate</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_math_Rect.html">goog.math.Rect</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_math_Size.html">goog.math.Size</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_net_errorcode.js.html">goog.net.ErrorCode</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_net_eventtype.js.html">goog.net.EventType</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_net_XhrIo.html">goog.net.XhrIo</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_net_XhrMonitor_.html">goog.net.XhrMonitor</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_net_xmlhttp.js.html">goog.net.XmlHttp</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_object_object.js.html">goog.object</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_string_string.js.html">goog.string</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_structs_structs.js.html">goog.structs</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_structs_Map.html">goog.structs.Map</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_structs_Set.html">goog.structs.Set</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_style_style.js.html">goog.style</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/class_goog_Timer.html">goog.Timer</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_useragent_useragent.js.html">goog.userAgent</a></li>
<li><a href="http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_useragent_product.js.html">goog.userAgent.product</a></li>
<li>goog.window</li>
</ul>
<p>It is build via the closure compiler itself, building from a set of <code>goog.require()</code> calls :)</p>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/closure-lite/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Javascript Inheritance Patterns: Learning from Closure</title>
		<link>http://ajaxian.com/archives/javascript-inheritance-patterns-learning-from-closure</link>
		<comments>http://ajaxian.com/archives/javascript-inheritance-patterns-learning-from-closure#comments</comments>
		<pubDate>Fri, 13 Nov 2009 22:04:01 +0000</pubDate>
		<dc:creator>Michael Mahemoff</dc:creator>
				<category><![CDATA[Closure]]></category>
		<category><![CDATA[Front Page]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7928</guid>
		<description><![CDATA[The library portion of Google's Closure not only gives us a new API to work with, but also adds another piece of mature code to the public domain, where it can be studied and scrutinized. Something we might normally have done with View Source if not for the compression techniques in effect. A new article <a href="http://ajaxian.com/archives/javascript-inheritance-patterns-learning-from-closure">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>The library portion of Google's <a href="http://code.google.com/closure/">Closure</a> not only gives us a new API to work with, but also adds another piece of mature code to the public domain, where it can be <a href="http://webreflection.blogspot.com/2009/11/google-closure-im-not-impressed.html">studied</a> and <a href="http://www.sitepoint.com/blogs/2009/11/12/google-closure-how-not-to-write-javascript/#">scrutinized</a>. Something we might normally have done with View Source if not for the compression techniques in effect.</p>
<p>A new article by Michael Bolin looks at <a href="http://bolinfest.com/javascript/inheritance.php">inheritance patterns in Javascript</a>, with a special focus on Closure. He does a thorough job of weighing up Closure's use of the pseudoclassical inheritance pattern against what Doug Crockford labels the functional pattern.</p>
<p>Pseudoclassical inheritance (Closure):</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-3');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-3">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">/**</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> * @param {string} phoneNumber</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> * @param {string=} signature</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> * @constructor</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> * @extends {Phone}</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> */</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">SmartPhone = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>phoneNumber, signature<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; Phone.<span style="color: #006600;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>, phoneNumber<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900; font-style: italic;">/**</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">&nbsp; &nbsp;* @type {string}</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">&nbsp; &nbsp;* @private</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">signature_</span> = signature || <span style="color: #3366CC;">'sent from '</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">getPhoneNumber</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">goog.<span style="color: #006600;">inherits</span><span style="color:#006600; font-weight:bold;">&#40;</span>SmartPhone, Phone<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">/**</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> * @param {string} emailAddress</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> * @param {string} message</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;"> */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">SmartPhone.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">sendEmail</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>emailAddress, message<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900; font-style: italic;">// Assume sendMessage() is globally available.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; sendMessage<span style="color:#006600; font-weight:bold;">&#40;</span>emailAddress, message + <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> + <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">signature_</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">/** @override */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">SmartPhone.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">getDescription</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">return</span> SmartPhone.<span style="color: #006600;">superClass_</span>.<span style="color: #006600;">getDescription</span>.<span style="color: #006600;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color:#006600; font-weight:bold;">&#41;</span> +</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">' It can also send email messages.'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> smartPhone = <span style="color: #003366; font-weight: bold;">new</span> SmartPhone<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'5555555'</span>, <span style="color: #3366CC;">'Adios'</span><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
<p>Functional inheritance:</p>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-4');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-4">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> smartPhone = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>spec<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> that = phone<span style="color:#006600; font-weight:bold;">&#40;</span>spec<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; spec.<span style="color: #006600;">signature</span> = spec.<span style="color: #006600;">signature</span> || <span style="color: #3366CC;">"sent from "</span> + that.<span style="color: #006600;">getPhoneNumber</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; that.<span style="color: #006600;">sendEmail</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span>emailAddress, message<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// Assume sendMessage() is globally available.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; sendMessage<span style="color:#006600; font-weight:bold;">&#40;</span>emailAddress, message + <span style="color: #3366CC;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span> + spec.<span style="color: #006600;">signature</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> super_getDescription = that.<span style="color: #006600;">superior</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">"getDescription"</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; that.<span style="color: #006600;">getDescription</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> super_getDescription<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> + <span style="color: #3366CC;">" It can also send email messages."</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #000066; font-weight: bold;">return</span> that;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> mySmartPhone = smartPhone<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color: #3366CC;">"phoneNumber"</span>: <span style="color: #3366CC;">"5555555"</span>, <span style="color: #3366CC;">"signature"</span>: <span style="color: #3366CC;">"Adios"</span><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/javascript-inheritance-patterns-learning-from-closure/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Closure Graphics Fun</title>
		<link>http://ajaxian.com/archives/closure-graphics-fun</link>
		<comments>http://ajaxian.com/archives/closure-graphics-fun#comments</comments>
		<pubDate>Tue, 10 Nov 2009 11:45:34 +0000</pubDate>
		<dc:creator>Dion Almaer</dc:creator>
				<category><![CDATA[Closure]]></category>
		<category><![CDATA[Front Page]]></category>

		<guid isPermaLink="false">http://ajaxian.com/?p=7899</guid>
		<description><![CDATA[Stephen Thomas has been experimenting with Closure and the graphics libraries: This does something similiar to what I do on Stark, my visual mud project [github page] that uses the Processing JS library and the HTML 5 &#60;canvas&#62; element, but instead of creating a draw function that is executed x amounts per seconds, you just <a href="http://ajaxian.com/archives/closure-graphics-fun">Read the rest...</a>]]></description>
			<content:encoded><![CDATA[<p>Stephen Thomas has been <a href="http://teebes.com/blog/19/">experimenting with Closure</a> and the <a href="http://teebes.com/closure/">graphics libraries</a>:</p>
<blockquote><p>
This does something similiar to what I do on Stark, my visual mud project [github page] that uses the Processing JS library and the HTML 5 &lt;canvas&gt; element, but instead of creating a draw function that is executed x amounts per seconds, you just call a draw function and assign it to a variable for future interactions. Here is the source code for this example (you can also just look at the current page's source):
</p></blockquote>
<div class="igBar"><a href="javascript:showCodeTxt('javascript-6');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">JAVASCRIPT:</span>
<div id="javascript-6">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> graphics = goog.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">createGraphics</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">200</span>, <span style="color:#800000;">150</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// define the colors for the squares and the dot</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> square_fill = <span style="color: #003366; font-weight: bold;">new</span> goog.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">SolidFill</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'yellow'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> square_stroke = <span style="color: #003366; font-weight: bold;">new</span> goog.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">Stroke</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">2</span>, <span style="color: #3366CC;">'green'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> dot_fill = <span style="color: #003366; font-weight: bold;">new</span> goog.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">SolidFill</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'blue'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> dot_stroke = <span style="color: #003366; font-weight: bold;">new</span> goog.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">Stroke</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">1</span>, <span style="color: #3366CC;">'black'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// the dot's initial position</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> dot = <span style="color:#006600; font-weight:bold;">&#123;</span>x: <span style="color:#800000;">1</span>, y: <span style="color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#125;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// properties&nbsp; &nbsp; </span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> size = <span style="color:#800000;">40</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> margin = <span style="color:#800000;">5</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> width = size - margin;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> num_rows = <span style="color:#800000;">3</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> num_cols = <span style="color:#800000;">4</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// draw the squares</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> x = <span style="color:#800000;">0</span>; x &lt;num_cols; x++<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> y = <span style="color:#800000;">0</span>; y &lt;num_rows; y++<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; graphics.<span style="color: #006600;">drawRect</span><span style="color:#006600; font-weight:bold;">&#40;</span>margin + x * size, margin + y * size, width, width, square_stroke, square_fill<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// draw the dot</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'graphic'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = graphics.<span style="color: #006600;">drawEllipse</span><span style="color:#006600; font-weight:bold;">&#40;</span>margin + dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'x'</span><span style="color:#006600; font-weight:bold;">&#93;</span> * size + width / <span style="color:#800000;">2</span>, margin + dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'y'</span><span style="color:#006600; font-weight:bold;">&#93;</span> * size + width <span style="color: #0066FF;">/ <span style="color:#800000;">2</span>, width / <span style="color:#800000;">4</span>, width /</span> <span style="color:#800000;">4</span>, dot_stroke, dot_fill<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// call if the dot's position changes</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; redraw_dot = <span style="color: #003366; font-weight: bold;">function</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'graphic'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color: #006600;">setCenter</span><span style="color:#006600; font-weight:bold;">&#40;</span>margin + dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'x'</span><span style="color:#006600; font-weight:bold;">&#93;</span> * size + width / <span style="color:#800000;">2</span>, margin + dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'y'</span><span style="color:#006600; font-weight:bold;">&#93;</span> * size + width / <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// key event handler</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> key_handler = <span style="color: #003366; font-weight: bold;">new</span> goog.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyHandler</span><span style="color:#006600; font-weight:bold;">&#40;</span>document<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> key_event = <span style="color: #003366; font-weight: bold;">function</span> <span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>e.<span style="color: #006600;">keyCode</span> == goog.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyCodes</span>.<span style="color: #006600;">UP</span> &amp;&amp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'y'</span><span style="color:#006600; font-weight:bold;">&#93;</span>&gt; <span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'y'</span><span style="color:#006600; font-weight:bold;">&#93;</span> -= <span style="color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>e.<span style="color: #006600;">keyCode</span> == goog.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyCodes</span>.<span style="color: #006600;">RIGHT</span> &amp;&amp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'x'</span><span style="color:#006600; font-weight:bold;">&#93;</span> &lt;= num_cols - <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'x'</span><span style="color:#006600; font-weight:bold;">&#93;</span> += <span style="color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>e.<span style="color: #006600;">keyCode</span> == goog.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyCodes</span>.<span style="color: #006600;">DOWN</span> &amp;&amp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'y'</span><span style="color:#006600; font-weight:bold;">&#93;</span> &lt;= num_rows - <span style="color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'y'</span><span style="color:#006600; font-weight:bold;">&#93;</span> += <span style="color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>e.<span style="color: #006600;">keyCode</span> == goog.<span style="color: #006600;">events</span>.<span style="color: #006600;">KeyCodes</span>.<span style="color: #006600;">LEFT</span> &amp;&amp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'x'</span><span style="color:#006600; font-weight:bold;">&#93;</span>&gt; <span style="color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dot<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color: #3366CC;">'x'</span><span style="color:#006600; font-weight:bold;">&#93;</span> -= <span style="color:#800000;">1</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; redraw_dot<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// put everything together</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; goog.<span style="color: #006600;">events</span>.<span style="color: #006600;">listen</span><span style="color:#006600; font-weight:bold;">&#40;</span>key_handler, <span style="color: #3366CC;">'key'</span>, key_event<span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; graphics.<span style="color: #006600;">render</span><span style="color:#006600; font-weight:bold;">&#40;</span>document.<span style="color: #006600;">getElementById</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #3366CC;">'shapes'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
</ol>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://ajaxian.com/archives/closure-graphics-fun/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

