<?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"
	>

<channel>
	<title>Mike G in NYC &#187; JavaScript</title>
	<atom:link href="http://www.lovemikeg.com/blog/category/javascript/feed" rel="self" type="application/rss+xml" />
	<link>http://www.lovemikeg.com/blog</link>
	<description>Mike G's Thoughts on the Web, Code, and Life in The City</description>
	<pubDate>Wed, 20 Aug 2008 04:06:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>A Week in JavaScript Patterns: The Module</title>
		<link>http://www.lovemikeg.com/blog/2008/08/19/a-week-in-javascript-patterns-the-module/</link>
		<comments>http://www.lovemikeg.com/blog/2008/08/19/a-week-in-javascript-patterns-the-module/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 03:55:34 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=198</guid>
		<description><![CDATA[The Module is a brilliant design pattern which demonstrates the elegance of the JavaScript language by exploiting closure (one of JavaScript&#8217;s most powerful features) to create private members. The Module makes use of Self-invocation making it useful as an application wrapper.
This pattern was originally discovered and named by Douglas Crockford.
Motivation
By default, there is no natural [...]]]></description>
			<content:encoded><![CDATA[<p>The Module is a brilliant design pattern which demonstrates the elegance of the JavaScript language by exploiting closure (one of JavaScript&#8217;s most powerful features) to create private members. The Module makes use of <a href="/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/">Self-invocation</a> making it useful as an application wrapper.</p>
<p>This pattern was originally discovered and named by <a href="http://crockford.com">Douglas Crockford</a>.</p>
<h3>Motivation</h3>
<p>By default, there is no natural data hiding functionality in the JavaScript language. As developers push the limits by continually creating more complex applications, the need for private object members becomes increasingly apparent.</p>
<h3>Implementation</h3>
<p>Modules are simply a standard self-invoking function who&#8217;s return value is an object of properties and methods which serve as a public API. In the example below, <samp>foo.bar</samp> is not being set to the value of the anonymous function but rather the object that is returned by the anonymous function.</p>
<pre class="prettyprint">
foo.bar = (function () {
    var baz = function () {};
    var bif = function () {};

    return {
        'thud' : function () {},
        'grunt' : function () {}
    };
})();
</pre>
<p><samp>foo.bar</samp> now has an object as its value which contains two methods: <samp>thud</samp> and <samp>grunt</samp>. <samp>baz</samp> and <samp>bif</samp> are not available publicly, however <samp>thud</samp> and <samp>grunt</samp> still have direct access to them through closure.</p>
<h3>Conclusion</h3>
<p>With the ability to implement public and private members in an API, developers now have the ability to create robust APIs in JavaScript. This allows developers to create powerful applications while exposing only what is necessary to make it function.</p>
<h3>Posts in this Series</h3>
<ul>
<li><strong>Sunday:</strong> <a href="/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/">Self-invocation</a></li>
<li><strong>Monday:</strong> <a href="/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/">Load Time Configuration</a></li>
<li><strong>Tuesday:</strong> The Module</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/08/19/a-week-in-javascript-patterns-the-module/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Week in JavaScript Patterns: Load Time Configuration</title>
		<link>http://www.lovemikeg.com/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/</link>
		<comments>http://www.lovemikeg.com/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 02:12:21 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=175</guid>
		<description><![CDATA[Load time configuration is the process where a JavaScript application configures itself as it is being loaded. This pattern is most commonly found in libraries in which they configure themselves at load time to be optimized for a particular browser.
Load time configuration is also known as load time branching.
Motivation
The primary motivation behind load time configuration [...]]]></description>
			<content:encoded><![CDATA[<p>Load time configuration is the process where a JavaScript application configures itself as it is being loaded. This pattern is most commonly found in libraries in which they configure themselves at load time to be optimized for a particular browser.</p>
<p>Load time configuration is also known as load time branching.</p>
<h3>Motivation</h3>
<p>The primary motivation behind load time configuration is to optimize conditional operations such as generating XMLHttpRequest instances or adding event listeners. Since both operations vary amongst clients, specific conditions must be checked before proceeding. The load time configuration pattern runs once at load time and sets the resulting value so that it doesn&#8217;t need to be checked again.</p>
<h3>Implementation</h3>
<p>The most common technique for implementing load time configuration is by way of a <a href="http://www.lovemikeg.com/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/">Self-invoking function</a> which returns the correctly configured value.</p>
<p>The example below demonstrates how load time configuration can be used to normalize getting an XMLHttpRequest object.</p>
<pre class="prettyprint">
var getXHR = (function () {
    if (window.XMLHttpRequest) {
        return function () {
            return new XMLHttpRequest;
        }
    }
    else if (window.ActiveXObject) {
        return function () {
            /* Msxml2 and Msxml3 checkes have been omitted
             * for simplicity's sake */
            return new ActiveXObject('Microsoft.XMLHTTP');
        }
    }
})();
</pre>
<p>First, a <samp>getXHR</samp> variable is declared and it&#8217;s value is being assigned by the self-invoking function that follows. Upon execution, a conditional is run which determines the correct method of obtaining an XMLHttpRequest object. When a match is found, a wrapper function is returned and stored as the value for <samp>getXHR</samp> variable.</p>
<h3>Conclusion</h3>
<p>The load time conditional pattern is used to configure a conditional value at load time. The result is a fully optimized value, specific to the the environment in which it is to be used.</p>
<h3>Posts in this Series</h3>
<ul>
<li><strong>Sunday:</strong> <a href="/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/">Self-invocation</a></li>
<li><strong>Monday:</strong> Load Time Configuration</li>
<li><strong>Tuesday:</strong> <a href="/blog/2008/08/19/a-week-in-javascript-patterns-the-module/">The Module</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A Week in JavaScript Patterns: Self-invocation</title>
		<link>http://www.lovemikeg.com/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/</link>
		<comments>http://www.lovemikeg.com/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 18:20:02 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=156</guid>
		<description><![CDATA[I would like to begin this series of posts with one of the most useful and commonplace patterns in my code. Arguably, this can be considered a feature of the JavaScript language rather than a design pattern; however, when considering the contexts in which it is applied, I regard it as a pattern.
Self-invocation (also known [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to begin this series of posts with one of the most useful and commonplace patterns in my code. Arguably, this can be considered a feature of the JavaScript language rather than a design pattern; however, when considering the contexts in which it is applied, I regard it as a pattern.</p>
<p>Self-invocation (also known as auto-invocation) is when a function executes immediately upon it&#8217;s definition. This is a core pattern and serves as the foundation for many other patterns of JavaScript development. </p>
<h3>Motivation</h3>
<p>The primary motivation behind self-invoking functions is to create scope. In JavaScript, only functions have scope. Any time variables are defined outside of a function, they are carelessly dumped into the global object. </p>
<h3>Implementation</h3>
<p>A self-invoking function is a standard function, just with a set of parentheses appended to the end.</p>
<pre class="prettyprint">
function () {
    var foo = 'Hello';
    var bar = 'world';
    var baz = [foo, bar];
    alert(baz.join(', '));
}();
</pre>
<p>The above example defines an anonymous function. This creates a literal function, yet since no name is attributed to it, the value is never stored. The trailing parenthesis tell the function to execute, just as if you were calling a named function.</p>
<p>Upon execution, the above function creates three variables, formats them, and alerts them to the user. Once the function terminates, the variables are discarded and the global object remains unchanged.</p>
<h4>Distinguishing from Actual Functions</h4>
<p>Given the oddness of the pattern (and lack of widespread understanding), it is very possible for developers to misinterpret this pattern as an actual function. It it <a href="http://peter.michaux.ca/article/8117">recommended</a> that an extra set of parentheses wrap the function definition as well so to provide a visual clue to the developer that the function isn&#8217;t a normal function. The result would be as follows.</p>
<pre class="prettyprint">
(function () {

    var foo = 'Hello';
    var bar = 'world';
    var baz = [foo, bar];
    alert(baz.join(', '));

})();
</pre>
<h4>Passing Parameters</h4>
<p>In the event where a self-invoking function requires parameters, they can be passed in the same manor that you would a regular function.</p>
<p>The following example applies an &#8220;negative&#8221; class on every input element who&#8217;s numeric value is below 0.</p>
<pre class="prettyprint">
(function (elements) {

    for (var i = 0; i < elements.length; i++) {
        if ((elements[i].value * 1) < 0) {
            elements[i].className = 'negative';
        }
    };

})(document.getElementsByTagName('input'));
</pre>
<h4>Executing in Another Scope</h4>
<p>Even though the function is executing within its own local scope, the <samp>this</samp> keyword will still refer to the global object. </p>
<p>The following example uses the <samp>Function.call()</samp> method to execute a self-invoking function within the scope of the first table element on the page.</p>
<pre class="prettyprint">
(function (elements) {

    for (var i = 5; i < this.rows.length; i++) {
        this.rows[i].className = 'hide';
    }

}).call(document.getElementsByTagName('table')[0]);
</pre>
<h3>Conclusion</h3>
<p>In an effort to protect the global object, all JavaScript applications should be written within a self-invoking function. This will create an application scope in which variables can be created without the fear of them colliding with other applications.</p>
<p>If a global variable is needed, developers must take the extra step by setting them directly within the window object. For example <samp>window.foo = &#8216;bar&#8217;;</samp>. </p>
<p>Self-invocation is a fundamental pattern of professional JavaScript development. Nearly every pattern in this weeks catalog uses it as a base to create scope, closure, or to configure cross-platform objects on-the-fly.</p>
<p>Stay tuned folks. This will be a good week.</p>
<h3>Posts in this Series</h3>
<ul>
<li><strong>Sunday:</strong> Self-invocation</li>
<li><strong>Monday:</strong> <a href="/blog/2008/08/18/a-week-in-javascript-patterns-load-time-configuration/">Load Time Configuration</a></li>
<li><strong>Tuesday:</strong> <a href="/blog/2008/08/19/a-week-in-javascript-patterns-the-module/">The Module</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/08/17/a-week-in-javascript-patterns-self-invocation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ajax for PHP Developers</title>
		<link>http://www.lovemikeg.com/blog/2008/07/26/ajax-for-php-developers/</link>
		<comments>http://www.lovemikeg.com/blog/2008/07/26/ajax-for-php-developers/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 15:45:03 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=114</guid>
		<description><![CDATA[Earlier this week I gave an Ajax presentation for NYPHP. It felt a little strange presenting a JavaScript topic to a bunch of PHP developers, but I made it come back to PHP by demonstrating a the latest Panda PHP package which is only in incubation at the moment. (I&#8217;ll formally announce that in a [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this week I gave an Ajax presentation for <a href="http://nyphp.org/">NYPHP</a>. It felt a little strange presenting a JavaScript topic to a bunch of PHP developers, but I made it come back to PHP by demonstrating a the latest <a href="http://pandaphp.org/">Panda PHP</a> package which is only in incubation at the moment. (I&#8217;ll formally announce that in a few weeks. Until then, you&#8217;ll have to come to more NYPHP meetings!)</p>
<p>This was my first presentation at NYPHP. It was also the first time I ever went to a formal meeting where we didn&#8217;t just network and drink beer (although there was plenty of that following the presentation).</p>
<p>You can <a href="http://www.slideshare.net/mgirouard/ajax-for-php-developers">view</a> or <a href="http://www.slideshare.net/signup?from_source=http%3A%2F%2Fwww.slideshare.net%2Fmgirouard%2Fajax-for-php-developers&#038;from=download">download</a> the presentation at Slideshare. I also have the <a href="/downloads/talks/Ajax-for-PHP-Developers/code.zip">sample code</a> which I used to demonstrate my concepts.</p>
<p>Enjoy.</p>
<div style="width:425px;text-align:left" id="__ss_524853"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/mgirouard/ajax-for-php-developers?src=embed" title="Ajax for PHP Developers">Ajax for PHP Developers</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=ajax-for-php-developers-1216780112990882-8"/><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=ajax-for-php-developers-1216780112990882-8" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">view <a href="http://www.slideshare.net/mgirouard/ajax-for-php-developers?src=embed" title="View Ajax for PHP Developers on SlideShare">presentation</a> (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/nyphp">nyphp</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/php">php</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/ajax">ajax</a>)</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/07/26/ajax-for-php-developers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript from Scratch: Parts Three and Four</title>
		<link>http://www.lovemikeg.com/blog/2008/06/29/javascript-from-scratch-parts-three-and-four/</link>
		<comments>http://www.lovemikeg.com/blog/2008/06/29/javascript-from-scratch-parts-three-and-four/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 03:59:45 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Talks]]></category>

		<category><![CDATA[events]]></category>

		<category><![CDATA[web-development]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=113</guid>
		<description><![CDATA[I&#8217;ve uploaded two additional talks which I recently gave covering the basics of events and application development in JavaScript. This continues on with the talks I added earlier this month.
Part Three: Events

 &#124; View &#124; Upload your own

Part Four: Writing JavaScript Applications

 &#124; View &#124; Upload your own

Other Posts in this Series

JavaScript From Scratch: Parts [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve uploaded two additional talks which I recently gave covering the basics of events and application development in JavaScript. This continues on with the <a href="http://www.lovemikeg.com/blog/2008/06/07/javascript-from-scratch-parts-one-and-two/">talks I added</a> earlier this month.</p>
<h3>Part Three: Events</h3>
<div id="__ss_459948" style="width:425px;text-align:left"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=events-1213149665824329-8" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=events-1213149665824329-8" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img style="border:0px none;margin-bottom:-5px" src="http://static.slideshare.net/swf/logo_embd.png" alt="SlideShare" /></a> | <a title="View JavaScript From Scratch: Events on SlideShare" href="http://www.slideshare.net/mgirouard/javascript-from-scratch-events?src=embed">View</a> | <a href="http://www.slideshare.net/upload?src=embed">Upload your own</a></div>
</div>
<h3>Part Four: Writing JavaScript Applications</h3>
<div id="__ss_492158" style="width:425px;text-align:left"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=writing-javascript-applications-1214797250451651-9" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=writing-javascript-applications-1214797250451651-9" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img style="border:0px none;margin-bottom:-5px" src="http://static.slideshare.net/swf/logo_embd.png" alt="SlideShare" /></a> | <a title="View JavaScript From Scratch: Writing Java Script Applications on SlideShare" href="http://www.slideshare.net/mgirouard/javascript-from-scratch-writing-java-script-applications?src=embed">View</a> | <a href="http://www.slideshare.net/upload?src=embed">Upload your own</a></div>
</div>
<h3>Other Posts in this Series</h3>
<ul>
<li><a href="http://www.lovemikeg.com/blog/2008/06/07/javascript-from-scratch-parts-one-and-two/">JavaScript From Scratch: Parts One and Two</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/06/29/javascript-from-scratch-parts-three-and-four/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Improving the Module</title>
		<link>http://www.lovemikeg.com/blog/2008/06/17/improving-the-module/</link>
		<comments>http://www.lovemikeg.com/blog/2008/06/17/improving-the-module/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 04:52:27 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[the module]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=111</guid>
		<description><![CDATA[
Update: In my code example below, I make use of a self variable. This probably isn&#8217;t the best idea in hindsight since JavaScript reserves self as a secondary reference to window. 

I’m always fascinated by the JavaScript language. What impressed me most, almost a year ago, was my discovery of Douglas Crockford’s module pattern. This [...]]]></description>
			<content:encoded><![CDATA[<div class="update">
<p><strong>Update:</strong> In my code example below, I make use of a <samp>self</samp> variable. This probably isn&#8217;t the best idea in hindsight since JavaScript reserves <samp>self</samp> as a secondary reference to <samp>window</samp>. </p>
</div>
<p>I’m always fascinated by the JavaScript language. What impressed me most, almost a year ago, was my discovery of Douglas Crockford’s module pattern. This was my first taste of what I consider to be the most intriguing thing in programming: <a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29">closure</a>. I didn’t understand the concept of closures when I first saw it, but after getting deeper and deeper into the language, it finally clicked. At that point I realized the potential of this type of language.</p>
<p>A few days ago, Peter posted his list of <a href="http://peter.michaux.ca/article/7933">JavaScript warning words</a>. To my surprise, &#8220;this&#8221; made the list.</p>
<p>Don’t get me wrong, I’m well aware of JavaScripts scoping issues, but it was still startling to see such a common element of my code sitting next to words like with, void, and eval.</p>
<p>He&#8217;s right though. If you&#8217;re not careful, &#8220;this&#8221; could quickly become problematic. For example, a constructor method declared without &#8220;new&#8221; would result in &#8220;this&#8221; being a reference to window and not the newly created object&#8230; oops.</p>
<p>This also becomes a problem when you use &#8220;this&#8221; in callbacks used for events. When methods are applied as event handlers, &#8220;this&#8221; generally refers to the element on which the event was applied &#8212; not the object that the function lives in when you write the code.</p>
<p>Peter advocates the use of closure as a means to reduce dependency on &#8220;this.&#8221; Today, I discovered an interesting pattern which does just that. Instead of relying on the ambiguous &#8220;this&#8221;, the following code creates a &#8220;self&#8221; variable in the module which is available in the inner functions as a replacement for &#8220;this&#8221;.</p>
<pre class="prettyprint">
var mikeg = function () {
    /* Create an internal reference to self as a replacement for this */
    var self = {};

    /* Return out self and some methods which have access to itself */
    return self = {
        SomeConstructor : function () {
            console.log(window !== this);
            console.log(self === mikeg);
        },

        someCallback : function () {
            console.log(window !== this);
            console.log(self === mikeg);
        }
    };
}();
</pre>
<p>It seems so obvious now that my fingers have found their way toward this code, but then again, isn&#8217;t that always the case? Looking back, I&#8217;m sure I&#8217;ve seen this elseware, but much like my original discovery of the Module, it didn&#8217;t click until after a little while.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/06/17/improving-the-module/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript from Scratch: Parts One and Two</title>
		<link>http://www.lovemikeg.com/blog/2008/06/07/javascript-from-scratch-parts-one-and-two/</link>
		<comments>http://www.lovemikeg.com/blog/2008/06/07/javascript-from-scratch-parts-one-and-two/#comments</comments>
		<pubDate>Sun, 08 Jun 2008 04:39:21 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=108</guid>
		<description><![CDATA[I&#8217;ve put together a series of eight talks which covers the basics of the JavaScript language. Below are the first two which handle most of the introductory material. Next week, I will post two more which cover the event model and writing JavaScript applications. The week following that, will be an overview of the DOM [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put together a series of eight talks which covers the basics of the JavaScript language. Below are the first two which handle most of the introductory material. Next week, I will post two more which cover the event model and writing JavaScript applications. The week following that, will be an overview of the DOM and object-oriented JavaScript. In the last week I will post talks which cover AJAX and JavaScript best practices</p>
<p>This whole series presents a basic set of knowledge that I think any front-end developer should know.</p>
<h3 id="part-one">Part One: Getting Your Feet Wet</h3>
<p>This talk talks about the four basic building blocks of programming: variables, conditionals, loops and functions.</p>
<div id="__ss_445794" style="width:425px;text-align:left"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=getting-your-feed-wet-1212552357322016-9" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=getting-your-feed-wet-1212552357322016-9" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img style="border:0px none;margin-bottom:-5px" src="http://static.slideshare.net/swf/logo_embd.png" alt="SlideShare" /></a> | <a title="View JavaScript from Scratch: Getting Your Feet Wet on SlideShare" href="http://www.slideshare.net/mgirouard/getting-your-feed-wet?src=embed">View</a> | <a href="http://www.slideshare.net/upload?src=embed">Upload your own</a></div>
</div>
<h3 id="part-two">Part Two: Playing With Data</h3>
<p>This talk details the data types available in JavaScript applications. Strings, Numbers, Booleans, Arrays, and Objects are discussed. Functions as values has been omitted until a later talk.</p>
<div id="__ss_450597" style="width:425px;text-align:left"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=playing-with-data-1212720095504612-8" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=playing-with-data-1212720095504612-8" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;"><a href="http://www.slideshare.net/?src=embed"><img style="border:0px none;margin-bottom:-5px" src="http://static.slideshare.net/swf/logo_embd.png" alt="SlideShare" /></a> | <a title="View Playing With Data on SlideShare" href="http://www.slideshare.net/mgirouard/playing-with-data?src=embed">View</a> | <a href="http://www.slideshare.net/upload?src=embed">Upload your own</a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/06/07/javascript-from-scratch-parts-one-and-two/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Come See Me Speak at AJAXWorld West</title>
		<link>http://www.lovemikeg.com/blog/2008/05/04/come-see-me-speak-at-ajaxworld-west/</link>
		<comments>http://www.lovemikeg.com/blog/2008/05/04/come-see-me-speak-at-ajaxworld-west/#comments</comments>
		<pubDate>Mon, 05 May 2008 01:24:04 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[Talks]]></category>

		<category><![CDATA[conference]]></category>

		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/?p=106</guid>
		<description><![CDATA[Please excuse the break in my MVC series, I just want to announce that one of my talks has been accepted for AJAXWorld 2008 West. I will be presenting on The Beauty of JavaScript &#8212; a topic of great interest to me as of late.
If you want to see me speak, see if you can [...]]]></description>
			<content:encoded><![CDATA[<p>Please excuse the break in my MVC series, I just want to announce that one of my talks has been accepted for <a href="http://www.ajaxworld.com/">AJAXWorld 2008 West</a>. I will be presenting on <em>The Beauty of JavaScript</em> &#8212; a topic of great interest to me <a href="http://www.lovemikeg.com/blog/2007/09/22/barcamp-orlando-slides/">as of late</a>.</p>
<p>If you want to see me speak, see if you can get your boss to pay for your fare. The lineup for the recent AJAXWorld East was pretty phenomenal (<a href="http://crockford.com/">Doug Crockford</a> gave the keynote&#8230; need I say more?) and I&#8217;m certain this event will be even better. If you can&#8217;t get your boss to flip the bill, submit a proposal. At the time of this writing <a href="http://www.ajaxworld.com/general/papers.htm">the CFP is still open</a>.</p>
<p>For those of you who are interested, my session abstract is as follows:</p>
<h3>The Beauty of JavaScript</h3>
<blockquote><p>
JavaScript is one of the most interesting and misunderstood programming languages in common use today. Most developers will go their entire careers without realizing its full potential. It&#8217;s not often that you get a language that supports the feature set that JavaScript does, while still being as widely deployed. This talk will spotlight some some patterns surrounding JavaScript&#8217;s most elegant features such as closures, lambdas, object and array literals, object prototypes, private members and dynamic scope resolution &#8212; all without boring you to tears.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2008/05/04/come-see-me-speak-at-ajaxworld-west/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Autoloading Element References with the DOM</title>
		<link>http://www.lovemikeg.com/blog/2007/12/13/autoloading-element-references-with-the-dom/</link>
		<comments>http://www.lovemikeg.com/blog/2007/12/13/autoloading-element-references-with-the-dom/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 08:14:06 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/2007/12/13/autoloading-element-references-with-the-dom/</guid>
		<description><![CDATA[It&#8217;s been a long time since I sat down and wrote anything about JavaScript; and with Dustin&#8217;s new book on design patterns in JavaScript, I felt that this would be a good time to post about a pattern that I&#8217;ve found myself using often.
You&#8217;d be hard pressed to find a JavaScript application that doesn&#8217;t manipulate [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time since I sat down and wrote anything about JavaScript; and with Dustin&#8217;s new book on design patterns in JavaScript, I felt that this would be a good time to post about a pattern that I&#8217;ve found myself using often.</p>
<p>You&#8217;d be hard pressed to find a JavaScript application that doesn&#8217;t manipulate the DOM nowadays. Usually there are a few elements that are manipulated often enough for them to be stored away in a property someplace for easy reference. If this sounds like any application you&#8217;ve written, you may like this.</p>
<p>Lets assume I have a registration form where users sign up for an account on a site:</p>
<pre class="prettyprint">
MIKEG.widgetShop.registration = {
    'elements' : {
        'username'   : 'account-username',
        'password'   : 'account-password',
        'firstName'  : 'account-first-name',
        'lastName'   : 'account-last-name',
        'email'      : 'account-email',
        'messageBox' : 'system-messages'
    },

    'usernameExists' : function (sUserName) {
        // Code...
    },

    'validateData' : function () {
        // Code...
    },

    'renderMessage' : function (text, type) {
        // Code...
    }
};
</pre>
<p>The registration object stores an elements property which contains a set of property:value pairs which form the basis of this pattern. The property value contains the value of the ID attribute of the element we wish to reference.</p>
<p>When the DOM is in a usable state, you can safely load all of your element references into the elements property replacing the ID values with actual element references. </p>
<pre class="prettyprint">
YAHOO.util.Event.onDOMReady(function () {
    var elements = MIKEG.widgetShop.registration.elements;

    for (i in elements) {
        elements[i] = YAHOO.util.Dom.get(elements[i]);
    }
});
</pre>
<p>And there you have it. Now anywhere inside the registration object you can simply address the element you want to target by <samp>this.elements.whatever</samp>. I&#8217;ve come to find that not only is this convenient, but it reads well and reduces code density substantially. Just look at how nice the implemented <samp>renderMessage</samp> method gets:</p>
<pre class="prettyprint">
'renderMessage' : function (text, type) {
    this.messageBox.innerHTML = text;

    if (typeof type !== 'undefined') {
        YAHOO.util.Dom.addClass(this.messageBox, type);
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2007/12/13/autoloading-element-references-with-the-dom/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Introducing Planet JavaScript</title>
		<link>http://www.lovemikeg.com/blog/2007/10/17/introducing-planet-javascript/</link>
		<comments>http://www.lovemikeg.com/blog/2007/10/17/introducing-planet-javascript/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 05:03:35 +0000</pubDate>
		<dc:creator>mikeg</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.lovemikeg.com/blog/2007/10/17/introducing-planet-javascript/</guid>
		<description><![CDATA[Planets are nothing new. No no, not planets like in the solar system; planets like news aggregating sites. I&#8217;ve been reading some for quite a while now as a low-fat alternative to full-on feed readers like Google Reader or Bloglines. My current favorites include Planet PHP, Planet Python, and as of about a week ago, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://planet-javascript.com/"><img src="http://farm3.static.flickr.com/2381/1595397364_7fef50cee1_m.jpg" width="240" height="146" alt="Planet JavaScript" /></a>Planets are nothing new. No no, not planets like in the solar system; planets like news aggregating sites. I&#8217;ve been reading some for quite a while now as a low-fat alternative to full-on feed readers like <a href="http://reader.google.com/">Google Reader</a> or <a href="http://bloglines.com/">Bloglines</a>. My current favorites include <a href="http://planet-php.org/">Planet PHP</a>, <a href="http://planet.python.com/">Planet Python</a>, and as of about a week ago, <a href="http://planet-websecurity.com/">Planet Web Security</a>. It seems like there is a planet site for almost every subject matter. Especially ones related to coding. </p>
<p>This weekend I was surprised to discover that there was no planet for JavaScript related blogs. So <a href="http://planet-javascript.com/">I made it</a>. Inspired by one of Chris Shiflett&#8217;s recent posts about <a href="http://shiflett.org/blog/2007/sep/catching-up-and-keeping-up">how he made one</a>, I decided to give it a go and build one myself. All in all, it was a great experience and wasn&#8217;t all that difficult. I began Saturday afternoon and finished Sunday afternoon. Probably the hardest thing about the process was finding good JavaScript blogs. </p>
<p>Here&#8217;s a question for the community: <strong>Where are all the JavaScript bloggers?</strong></p>
<p>At any rate, it was an incredibly fun project and anyone who finds themselves reading a lot of feeds in a specific category, should try to whip one up. Here&#8217;s some of the basics things to keep in mind:</p>
<ul class="content">
<li>There are two main types of feeds floating around the internets today: RSS and Atom; both of which do the same thing but very differently. It would be worth the time if you took a moment to sit down and read up on them a bit. WikiPedia has examples of both <a href="http://en.wikipedia.org/wiki/Rss">RSS</a> and <a href="http://en.wikipedia.org/wiki/Atom_%28standard%29">Atom</a> feeds that you can dissect and learn from.</li>
<li>Content from other people&#8217;s blogs <em>will</em> interfere with your content. There is a good chance that you use the same ID attribute on something that someone else has and as a result your layout breaks. It&#8217;s also possible that they just have a poorly marked up site which will cause yours to fail validation. Either way, you need to clean up the bad content that will come your way. I suggest getting friendly with <a href="http://htmlpurifier.org/">HTMLPurifier</a>. It&#8217;s a gem.</li>
<li>Consider how you are going to store the data. If you are just going to cache the data in a flat file, you don&#8217;t need to do much; but if you plan on any amount of scalability, you&#8217;ll probably use a database. There are a lot of characters in XHTML that will cause databases to flip out. Make sure you have a good escaping routine to take care of those potentially dangerous characters. If you are a MySQL and PHP user, use <a href="http://php.net/mysql_real_escape_string"><samp>mysql_real_escape_string</samp></a>.</li>
<li>People post regularly on blogs so you need to update your planet regularly. You could have a nice admin area with a big shiny &#8220;Update&#8221; button but manual updates suck. Simple websites like this should run themselves. I created a cron job to call a command-line PHP script that fetches the latest headlines and saves them to my database every six hours.</li>
<li>Last but not least: Think about how you are going to prevent duplicate entries from being saved. I&#8217;m simply checking the posted date but I&#8217;m sure that some error will pop up. Another alternative would be to generate a md5 sum of the content and compare it to a sum of what&#8217;s stored in the database. That sounded like a lot of work and I quickly lost interest.</li>
</ul>
<p>I&#8217;ll post the source code soon. I hacked it together procedurally and am currently integrating it into another little project I have going which you will soon hear about.</p>
<p>Check the site out. Give me some feedback. Blog about JavaScript.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lovemikeg.com/blog/2007/10/17/introducing-planet-javascript/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
