<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Mellentine Design</title>
	
	<link>http://design.mellentine.com</link>
	<description>The maniacal musings of a pixel perfectionist</description>
	<pubDate>Wed, 03 Dec 2008 00:10:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/MellentineDesign" type="application/rss+xml" /><feedburner:emailServiceId>1825332</feedburner:emailServiceId><feedburner:feedburnerHostname>http://www.feedburner.com</feedburner:feedburnerHostname><item>
		<title>JAVASCRIPT: Simple date conversion from SQL to readable</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/473032897/</link>
		<comments>http://design.mellentine.com/2008/12/02/javascript-simple-date-conversion-from-sql-to-readable/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 00:10:21 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=29</guid>
		<description><![CDATA[I needed a simple date converter function from SQL dates (YYYY-MM-DD) to something readable (M/D/YYYY).  So I wrote this little function.  Maybe someone else will have some use for it.

1
2
3
var makeSQLDatePretty = function&#40;d&#41; &#123;
  return d.replace&#40;/([0-9]{4})-0?([0-9]{1,2})-0?([0-9]{1,2})/, '$2/$3/$1'&#41;;
&#125;;

Pass in a SQL date and the function trims leading zeros and returns a reformatted date.

1
2
var sqlDate = [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a simple date converter function from SQL dates (YYYY-MM-DD) to something readable (M/D/YYYY).  So I wrote this little function.  Maybe someone else will have some use for it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> makeSQLDatePretty <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> d.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/([0-9]{4})-0?([0-9]{1,2})-0?([0-9]{1,2})/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'$2/$3/$1'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;</pre></td></tr></table></div>

<p>Pass in a SQL date and the function trims leading zeros and returns a reformatted date.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sqlDate <span style="color: #339933;">=</span> <span style="color: #3366CC;">'2008-12-02'</span>;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>makeSQLDatePretty<span style="color: #009900;">&#40;</span>sqlDate<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// should alert '12/2/2008'</span></pre></td></tr></table></div>

<p>Crazy Europeans may want to change the replace regex with &#8216;$3/$2/$1&#8242;.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/12/02/javascript-simple-date-conversion-from-sql-to-readable/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/12/02/javascript-simple-date-conversion-from-sql-to-readable/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Smart, unobtrusive AJAX form submission with jQuery</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/400258615/</link>
		<comments>http://design.mellentine.com/2008/09/22/javascript-smart-unobtrusive-ajax-form-submission-with-jquery/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 23:44:22 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=19</guid>
		<description><![CDATA[A former coworker was telling me recently about MooTools and how the AJAX functions are so easy to use.  He sent me the following example:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
function attachedToOnSubmitOfAForm&#40;&#41;&#123;
        sp = $&#40;&#34;someForm&#34;&#41;;
        sp.addClass&#40;'loader'&#41;;
&#160;
        sp.send&#40;&#123;
    [...]]]></description>
			<content:encoded><![CDATA[<p>A former coworker was telling me recently about MooTools and how the AJAX functions are so easy to use.  He sent me the following example:<br />
<span id="more-19"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> attachedToOnSubmitOfAForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        sp <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;someForm&quot;</span><span style="color: #009900;">&#41;</span>;
        sp.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loader'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        sp.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                onComplete<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ....
                <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
                onFailure<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        ....
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Great concept, right?  No need to tell it where to send the data or what fields to send, since the form already contains that info.  It&#8217;s mostly unobtrusive, so any browser that doesn&#8217;t have JS enabled would still be able to submit.</p>
<p>So my immediate response was, &#8220;Very cool.  I&#8217;m sure a jQuery plugin either exists or could be created pretty easily to handle that.&#8221;</p>
<p>I built the following plugin in maybe 30 minutes, and had it tested in another 15.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">send</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		    <span style="color: #003366; font-weight: bold;">var</span> form <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				jQuery.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span>jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
					type     <span style="color: #339933;">:</span> form.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'method'</span><span style="color: #009900;">&#41;</span> || <span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
					url      <span style="color: #339933;">:</span> form.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #009900;">&#41;</span> || window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">,</span>
					data     <span style="color: #339933;">:</span> form.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>There are some of you that are wondering, &#8220;Why is this necessary? I can write my own jQuery.ajax() code every time.&#8221;  Yep, and that&#8217;s part the problem I&#8217;m trying to solve. The plugin is a shortcut for most of the jQuery.ajax() code you&#8217;d normally write and it makes unobtrusive form submission dead simple:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		complete <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>The function takes one parameter, an object that extends the <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options">jQuery.ajax method</a>.</p>
<p>Here&#8217;s a <a href="/demos/jquery-send?PHPSESSID=9cb4ef1a99dbc8493fefd3144427d1eb">demo</a> and the <a href="/downloads/jquery.send.js?PHPSESSID=9cb4ef1a99dbc8493fefd3144427d1eb">download</a>.</p>
<p><strong>2008-09-23</strong>: Updated <em>window.location</em> to <em>window.location.href</em> (Thanks Samori)</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/09/22/javascript-smart-unobtrusive-ajax-form-submission-with-jquery/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/09/22/javascript-smart-unobtrusive-ajax-form-submission-with-jquery/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Iterating through objects, the easy way</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/285844740/</link>
		<comments>http://design.mellentine.com/2008/05/08/javascript-iterating-through-objects-the-easy-way/#comments</comments>
		<pubDate>Thu, 08 May 2008 05:04:24 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=18</guid>
		<description><![CDATA[Objects in any ECMAScript language (Javascript, Actionscript, Jscript, etc) are very powerful for - among other things - storing data.  However, getting some information out of these objects can be a hassle sometimes.
I ran into this issue recently and wrote some cool little handlers for objects.  The following methods can be used to [...]]]></description>
			<content:encoded><![CDATA[<p>Objects in any ECMAScript language (Javascript, Actionscript, Jscript, etc) are very powerful for - among other things - storing data.  However, getting some information out of these objects can be a hassle sometimes.</p>
<p>I ran into this issue recently and wrote some cool little handlers for objects.  The following methods can be used to iterate through an array manually.  I wrote them for Actionscript, but they certainly work for Javascript - although I&#8217;d suggest one small modification (shown later).<span id="more-18"></span></p>
<p>Let&#8217;s get to the code.</p>
<p>In each of the &#8220;for in&#8221; loops below, I make sure to exclude any prototyped methods.  If I don&#8217;t, they&#8217;ll show up in the loop - which can be pretty bad.</p>
<p>The &#8216;first&#8217; method starts looping through the array, but returns the first item in the object as soon as it gets to it.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">first</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> s;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>The &#8216;last&#8217; method loops through the object, storing the current item in a variable.  When it finishes the loop, it returns that variable - the last item in the object.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">last</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> l <span style="color: #339933;">=</span> s;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> l;
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>The &#8216;previous&#8217; method loops through the object looking for the &#8217;subject&#8217; variable.  If it matches the variable with the current item, it returns the previous item - set after the if statement below (in the previous time through the loop).  If it never matches the variable or the previous item is never set, it will return the last item of the object.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">previous</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s <span style="color: #339933;">==</span> subject <span style="color: #339933;">&amp;</span>amp;&amp;amp; l <span style="color: #339933;">!==</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> l;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003366; font-weight: bold;">var</span> l <span style="color: #339933;">=</span> s;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>The &#8216;next&#8217; method loops through the object looking for the &#8217;subject&#8217; variable, as well.  However, when it matches the variable it sets a &#8216;found&#8217; flag.  The next time through the loop, the current item will be returned.  If it never matches the variable or the matched item is the last in the object, the first item will be returned.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">next</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span>;
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> s;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s <span style="color: #339933;">==</span> subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>So let&#8217;s do some examples.  My test object has 3 items - one of which contains an array:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myObject <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	apple  <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
		<span style="color: #3366CC;">'fuji'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'gala'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'red delicious'</span>
	<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	banana <span style="color: #339933;">:</span> <span style="color: #3366CC;">'chiquita'</span><span style="color: #339933;">,</span>
	orange <span style="color: #339933;">:</span> <span style="color: #3366CC;">'navel'</span>
<span style="color: #009900;">&#125;</span>;
&nbsp;
myObject.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// returns 'apple'</span>
myObject.<span style="color: #660066;">last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;  <span style="color: #006600; font-style: italic;">// returns 'orange'</span>
myObject.<span style="color: #660066;">previous</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'apple'</span><span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// returns 'orange'</span>
myObject.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'apple'</span><span style="color: #009900;">&#41;</span>;     <span style="color: #006600; font-style: italic;">// returns 'banana'</span>
myObject.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'banana'</span><span style="color: #009900;">&#41;</span>;    <span style="color: #006600; font-style: italic;">// returns 'orange'</span>
myObject.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'orange'</span><span style="color: #009900;">&#41;</span>;    <span style="color: #006600; font-style: italic;">// returns 'apple'</span></pre></div></div>

<p>Simple as that.</p>
<p>The one change that I would recommend looking into for Javascript is better checking for the &#8220;for in&#8221; loops.</p>
<p>Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>The hasOwnProperty property is recommended:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/05/08/javascript-iterating-through-objects-the-easy-way/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/05/08/javascript-iterating-through-objects-the-easy-way/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: onerror image magic</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258352541/</link>
		<comments>http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 14:44:47 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[html]]></category>

		<category><![CDATA[img]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/</guid>
		<description><![CDATA[HTML has a little-known event handler for &#60;img&#62; and &#60;body&#62; tags.  I&#8217;m going to focus on &#60;img&#62; tags and how you can use this to clean up some 404s.
First, just a quick note about this event handler.  You won&#8217;t find it in any W3C spec because it just isn&#8217;t there.  Why?  [...]]]></description>
			<content:encoded><![CDATA[<p>HTML has a little-known event handler for &lt;img&gt; and &lt;body&gt; tags.  I&#8217;m going to focus on &lt;img&gt; tags and how you can use this to clean up some 404s.<span id="more-17"></span></p>
<p>First, just a quick note about this event handler.  You won&#8217;t find it in any W3C spec because it just isn&#8217;t there.  Why?  I don&#8217;t know, but I do know that it&#8217;s supported by Firefox and Internet Explorer 6/7 - which is ~90% of the browser usage and possibly more (read: I need to fire up my Mac and test it).  Apparently, this event handler has been around for a long time - see this <a href="http://lists.w3.org/Archives/Public/www-html/2001Sep/0084.html" target="_blank">brief e-mail exchange</a> on the HTML users group.</p>
<p>Okay, let&#8217;s get started.  Recently, I was working with some external data where I didn&#8217;t know whether I would have an image with each item the data or not.  This is a simple problem that can be solved using server side code (since the data feed needed to be parsed into a database table anyway).  However, I found that the links to some of the images returned 404 errors.  I&#8217;m not a usability expert, but have broken images looks pretty bad, even if you use alt attributes.  The onerror event handler is perfect for this situation.  Here&#8217;s how it works:</p>
<p>You assign the attribute to the image tag with some sort of error handler:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;badimage.jpg&quot; onerror=&quot;fixImage(this);&quot; /&gt;</pre></td></tr></table></div>

<p>Then, create your error handler function.  You could replace the image with a &#8220;No image&#8221; image (like I did):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fixImage<span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'noimage.gif'</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Or you could just remove the image altogether:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fixImage<span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  img.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you want to read more about using onerror with &lt;body&gt; tags, <a href="http://developer.mozilla.org/" target="_blank">MDC</a> has some <a href="http://developer.mozilla.org/en/docs/DOM:window.onerror" target="_blank">documentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Internet Explorer’s attachEvent breaks ‘this’</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332781/</link>
		<comments>http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 18:27:47 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[DOM]]></category>

		<category><![CDATA[events]]></category>

		<category><![CDATA[Internet Explorer]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/</guid>
		<description><![CDATA[First of all, let me just say that I love jQuery.  It makes Javascript development so much faster.  I&#8217;m sure that Prototype is just as easy for those that use that daily, but I prefer jQuery.  And before you ask&#8230; Yes, I learned both.
That having been said, there are some applications where [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, let me just say that I love <a href="http://jquery.com/" target="_blank">jQuery</a>.  It makes Javascript development so much faster.  I&#8217;m sure that <a href="http://www.prototypejs.org/" target="_blank">Prototype</a> is just as easy for those that use that daily, but I prefer jQuery.  And before you ask&#8230; Yes, I learned both.</p>
<p>That having been said, there are some applications where I cannot use a Javascript library and I need to use the (longer) Javascript methods.  There&#8217;s nothing wrong with this - in fact, I find that I always learn something new.  Such was the case today.<span id="more-13"></span></p>
<p>I decided that I would attach some events using the addEventListener function.  I had always either used the <a href="http://www.w3.org/TR/DOM-Level-2-Events/" target="_blank">older method</a> of attaching events or some helper library.  So I checked out <a href="http://developer.mozilla.org/en/docs/DOM:element.addEventListener" target="_blank">the spec</a> on <a href="http://developer.mozilla.org/" target="_blank">MDC</a> and saw that Internet Explorer had its own version of this function called <a href="http://msdn2.microsoft.com/en-us/library/ms536343.aspx" target="_blank">attachEvent</a>.  I hate how Internet Explorer does things like this.  There are standards for a reason, you know.</p>
<p>Anyway, I wrote a simple function that would apply the event, but it was not working in Internet Explorer.  So I started debugging the issue.</p>
<p>&#8220;Is the event being attached?&#8221; - Yes</p>
<p>Is the event being attached to the right object?&#8221; - Yes</p>
<p>Can I alert some text in the event function?&#8221; - Yes&#8230; odd.</p>
<p>Here&#8217;s my function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">addEvent<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'mouseover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'over'</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
addEvent <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> event<span style="color: #339933;">,</span> func<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> func<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'on'</span><span style="color: #339933;">+</span>event<span style="color: #339933;">,</span> func<span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    el<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'on'</span><span style="color: #339933;">+</span>event<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> func;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;</pre></td></tr></table></div>

<p>It turns out that Internet Explorer doesn&#8217;t pass the &#8216;this&#8217; object to the event function.  &#8216;this&#8217; is this instance should be the object that had the event attached.</p>
<p>It&#8217;s no shock to people that know me that I hate Internet Explorer.  I even sell <a href="http://19352.spreadshirt.com/-/-/Shop/" target="_blank">T-shirts</a> declaring that fact.  But this is just stupid.</p>
<p>Why did Microsoft have to implement their own version of addEventListener?  Why did they have to implement it so horribly that it doesn&#8217;t return &#8216;this&#8217;?</p>
<p>I ended up writing a workaround that just used the older method of applying the event to the object.  Here&#8217;s the finished version:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">addEvent <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> event<span style="color: #339933;">,</span> func<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> func<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    el<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'on'</span><span style="color: #339933;">+</span>event<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> func;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;</pre></td></tr></table></div>

<p>It&#8217;s really just adding insult to injury, since the only reason I had to write this function is because Internet Explorer doesn&#8217;t handle the CSS :hover pseudo-class for DIV elements.</p>
<p>Anyone want a <a href="http://19352.spreadshirt.com/-/-/Shop/" target="_blank">T-shirt</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/</feedburner:origLink></item>
		<item>
		<title>LEARNING: 2008 monthly plan updated</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332782/</link>
		<comments>http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 17:56:43 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[learning]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/</guid>
		<description><![CDATA[The learning plan has been canceled for now.  Between work, side work and a new baby, I really don&#8217;t have time to learn as a separate task.  I guess I&#8217;ll just have to learn as I go along.
]]></description>
			<content:encoded><![CDATA[<p>The learning plan has been canceled for now.  Between work, side work and a new baby, I really don&#8217;t have time to learn as a separate task.  I guess I&#8217;ll just have to learn as I go along.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/</feedburner:origLink></item>
		<item>
		<title>LEARNING: 2008 monthly plan</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332783/</link>
		<comments>http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/#comments</comments>
		<pubDate>Tue, 01 Jan 2008 08:58:52 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[learning]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/</guid>
		<description><![CDATA[Since it is the new year already, I&#8217;ve decided to plan my learning schedule for the next 12 months.  Here&#8217;s the plan so far (subject to change):

January: JavaServer Pages
February: Java
March: Java (continued)
April: MySQL 5
May: MySQL 5 (continued)
June: SQLite
July: Python
August: Python (continued)
September: Perl
October: Perl (continued)
November: Ext
December: Ruby

These should really push me out of my comfort [...]]]></description>
			<content:encoded><![CDATA[<p>Since it is the new year already, I&#8217;ve decided to plan my learning schedule for the next 12 months.  Here&#8217;s the plan so far (subject to change):</p>
<ul>
<li><strong>January</strong>: <a href="http://en.wikipedia.org/wiki/Javaserver_pages" target="_blank">JavaServer Pages</a></li>
<li><strong>February</strong>: <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" target="_blank">Java</a></li>
<li><strong>March</strong>: <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" target="_blank">Java</a> (continued)</li>
<li><strong>April</strong>: <a href="http://en.wikipedia.org/wiki/MySQL" target="_blank">MySQL</a> 5</li>
<li><strong>May</strong>: <a href="http://en.wikipedia.org/wiki/MySQL" target="_blank">MySQL</a> 5 (continued)</li>
<li><strong>June</strong>: <a href="http://en.wikipedia.org/wiki/Sqlite" target="_blank">SQLite</a></li>
<li><strong>July</strong>: <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" target="_blank">Python</a></li>
<li><strong>August</strong>: <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" target="_blank">Python</a> (continued)</li>
<li><strong>September</strong>: <a href="http://en.wikipedia.org/wiki/Perl" target="_blank">Perl</a></li>
<li><strong>October</strong>: <a href="http://en.wikipedia.org/wiki/Perl" target="_blank">Perl</a> (continued)</li>
<li><strong>November</strong>: <a href="http://en.wikipedia.org/wiki/Ext_%28javascript_library%29" target="_blank">Ext</a></li>
<li><strong>December</strong>: <a href="http://en.wikipedia.org/wiki/Ruby_programming_language" target="_blank">Ruby</a></li>
</ul>
<p>These should really push me out of my comfort zone.  I&#8217;ll try to share book info and progress and I go along.  Wish me luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Method overloading</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332784/</link>
		<comments>http://design.mellentine.com/2007/12/04/javascript-method-overloading/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 04:20:08 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2007/12/04/javascript-method-overloading/</guid>
		<description><![CDATA[John Resig, one of my heroes and creator of the jQuery JavaScript library, wrote a great piece about overloading methods.  He created a dead simple function that shoulders most of the work.  Check it out:

1
2
3
4
5
6
7
8
9
function addMethod&#40;object, name, fn&#41;&#123;
  var old = object&#91; name &#93;;
  object&#91; name &#93; = function&#40;&#41;&#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ejohn.org/" title="John Resig" target="_blank">John Resig</a>, one of my heroes and creator of the <a href="http://jquery.com/" title="jQuery" target="_blank">jQuery</a> JavaScript library, wrote a <a href="http://ejohn.org/blog/javascript-method-overloading/" title="JavaScript method overloading" target="_blank">great piece</a> about overloading methods.  He created a dead simple function that shoulders most of the work.  Check it out:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addMethod<span style="color: #009900;">&#40;</span>object<span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span> fn<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> old <span style="color: #339933;">=</span> object<span style="color: #009900;">&#91;</span> <span style="color: #000066;">name</span> <span style="color: #009900;">&#93;</span>;
  object<span style="color: #009900;">&#91;</span> <span style="color: #000066;">name</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> fn.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> arguments.<span style="color: #660066;">length</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> fn.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments <span style="color: #009900;">&#41;</span>;
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">typeof</span> old <span style="color: #339933;">==</span> <span style="color: #3366CC;">'function'</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> old.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments <span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here&#8217;s how you could use it to extend the User object that we <a href="http://design.mellentine.com/2007/12/01/javascript-creating-objects-and-methods/">created earlier</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">addMethod<span style="color: #009900;">&#40;</span>User.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;find&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Find all users...</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
addMethod<span style="color: #009900;">&#40;</span>User.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;find&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Find a user by name</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
addMethod<span style="color: #009900;">&#40;</span>User.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;find&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>first<span style="color: #339933;">,</span> last<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Find a user by first and last name</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>You can read more from John&#8217;s blog <a href="http://ejohn.org/blog/" title="John Resig blog" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2007/12/04/javascript-method-overloading/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2007/12/04/javascript-method-overloading/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Creating objects and methods</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332785/</link>
		<comments>http://design.mellentine.com/2007/12/01/javascript-creating-objects-and-methods/#comments</comments>
		<pubDate>Sat, 01 Dec 2007 18:07:08 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2007/12/01/javascript-creating-objects-and-methods/</guid>
		<description><![CDATA[That&#8217;s right, object-oriented Javascript.  Let&#8217;s get to it.  We&#8217;re going to make an object for storing and retrieving user information.
Let&#8217;s start with the base object:

1
2
var User = function&#40;firstName, lastName, emailAddress&#41; &#123;
&#125;

We have to initialize the variables so that they&#8217;re available to the rest of the methods of this object:

1
2
3
4
5
var User = function&#40;firstName, lastName, [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s right, object-oriented Javascript.  Let&#8217;s get to it.  We&#8217;re going to make an object for storing and retrieving user information.</p>
<p>Let&#8217;s start with the base object:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> User <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>firstName<span style="color: #339933;">,</span> lastName<span style="color: #339933;">,</span> emailAddress<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>We have to initialize the variables so that they&#8217;re available to the rest of the methods of this object:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> User <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>firstName<span style="color: #339933;">,</span> lastName<span style="color: #339933;">,</span> emailAddress<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">firstName</span> <span style="color: #339933;">=</span> firstName;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lastName</span> <span style="color: #339933;">=</span> lastName;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span> <span style="color: #339933;">=</span> emailAddress;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Then let&#8217;s start creating the methods:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">User.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  add<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User added: '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  changeEmail<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>email<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span> <span style="color: #339933;">=</span> email;
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'E-mail address for '</span><span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">' changed to: '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  getFullName<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">firstName</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lastName</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Lastly, let&#8217;s run the <code>add()</code> method when we setup a new user:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> User <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>firstName<span style="color: #339933;">,</span> lastName<span style="color: #339933;">,</span> emailAddress<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">firstName</span> <span style="color: #339933;">=</span> firstName;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lastName</span> <span style="color: #339933;">=</span> lastName;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span> <span style="color: #339933;">=</span> emailAddress;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Alright, that&#8217;s all done.  Now what do we do with this thing?</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// alerts 'User added: Michael Bolton'</span>
<span style="color: #003366; font-weight: bold;">var</span> michael <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Michael'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Bolton'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'mbolton@initech.com'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// alerts 'E-mail address for Michael Bolton changed to: michael.bolton@initrode.com'</span>
michael.<span style="color: #660066;">changeEmail</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'michael.bolton@initrode.com'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// alerts 'Hello, Michael'</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello, '</span> <span style="color: #339933;">+</span> michael.<span style="color: #660066;">firstName</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>Here it is in one big snippet:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> User <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>firstName<span style="color: #339933;">,</span> lastName<span style="color: #339933;">,</span> emailAddress<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">firstName</span> <span style="color: #339933;">=</span> firstName;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lastName</span> <span style="color: #339933;">=</span> lastName;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span> <span style="color: #339933;">=</span> emailAddress;
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
User.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  add<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'User added: '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  changeEmail<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>email<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span> <span style="color: #339933;">=</span> email;
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'E-mail address for '</span><span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">' changed to: '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">emailAddress</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  getFullName<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">firstName</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">lastName</span>;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// alerts 'User added: Michael Bolton'</span>
<span style="color: #003366; font-weight: bold;">var</span> michael <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> User<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Michael'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Bolton'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'mbolton@initech.com'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// alerts 'E-mail address for Michael Bolton changed to: michael.bolton@initrode.com'</span>
michael.<span style="color: #660066;">changeEmail</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'michael.bolton@initrode.com'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// alerts 'Hello, Michael'</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello, '</span> <span style="color: #339933;">+</span> michael.<span style="color: #660066;">firstName</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2007/12/01/javascript-creating-objects-and-methods/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2007/12/01/javascript-creating-objects-and-methods/</feedburner:origLink></item>
		<item>
		<title>FLASH: Recursively parse XML into an array</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332786/</link>
		<comments>http://design.mellentine.com/2007/12/01/flash-recursively-parse-xml-into-an-array/#comments</comments>
		<pubDate>Sat, 01 Dec 2007 17:43:55 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[actionscript]]></category>

		<category><![CDATA[flash]]></category>

		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2007/12/01/flash-recursively-parse-xml-into-an-array/</guid>
		<description><![CDATA[Flash does not make it easy to handle XML.  I&#8217;ve used some really bad code to help me parse arrays until I came up with this.  It doesn&#8217;t handle elements of the same name at the same level, but it can probably be modified to do so.

var myParsedXML = new Array&#40;&#41;;
&#160;
var myXML = [...]]]></description>
			<content:encoded><![CDATA[<p>Flash does not make it easy to handle XML.  I&#8217;ve used some really bad code to help me parse arrays until I came up with this.  It doesn&#8217;t handle elements of the same name at the same level, but it can probably be modified to do so.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myParsedXML = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> myXML = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
myXML.<span style="color: #0066CC;">ignoreWhite</span> = <span style="color: #000000; font-weight: bold;">true</span>;
myXML.<span style="color: #0066CC;">onLoad</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>success<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>success<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">parseXML</span><span style="color: #66cc66;">&#40;</span>myXML<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>;
&nbsp;
myXML.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;data.xml&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">function</span> parseFile<span style="color: #66cc66;">&#40;</span>xmlData<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> mainXMLElement = xmlData.<span style="color: #0066CC;">firstChild</span>.<span style="color: #0066CC;">childNodes</span>;
  <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i = 0; i <span style="color: #66cc66;">&amp;</span>lt; mainXMLElement.<span style="color: #0066CC;">length</span>; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    myParsedXML.<span style="color: #0066CC;">push</span><span style="color: #66cc66;">&#40;</span>intoArray<span style="color: #66cc66;">&#40;</span>mainXMLElement<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> intoArray<span style="color: #66cc66;">&#40;</span>xml_element<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> xml_array = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>xml_element.<span style="color: #0066CC;">hasChildNodes</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> cn = 0; cn <span style="color: #66cc66;">&amp;</span>lt; xml_element.<span style="color: #0066CC;">childNodes</span>.<span style="color: #0066CC;">length</span>; cn++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">nodeType</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        xml_array<span style="color: #66cc66;">&#91;</span>xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">nodeName</span><span style="color: #66cc66;">&#93;</span> = xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">firstChild</span>;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">attributes</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
          xml_array<span style="color: #66cc66;">&#91;</span>xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">nodeName</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">attributes</span> = xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">attributes</span>;
        <span style="color: #66cc66;">&#125;</span>
      <span style="color: #66cc66;">&#125;</span>
      <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
        xml_array<span style="color: #66cc66;">&#91;</span>xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span>.<span style="color: #0066CC;">nodeName</span><span style="color: #66cc66;">&#93;</span> = intoArray<span style="color: #66cc66;">&#40;</span>xml_element.<span style="color: #0066CC;">childNodes</span><span style="color: #66cc66;">&#91;</span>cn<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #b1b100;">return</span> xml_array;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2007/12/01/flash-recursively-parse-xml-into-an-array/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2007/12/01/flash-recursively-parse-xml-into-an-array/</feedburner:origLink></item>
	</channel>
</rss>
