<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; Namespacing</title>
	<atom:link href="http://www.zachleat.com/web/tag/namespacing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Mon, 06 Feb 2012 17:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Namespacing outside of the YAHOO Namespace</title>
		<link>http://www.zachleat.com/web/namespacing-outside-of-the-yahoo-namespace/</link>
		<comments>http://www.zachleat.com/web/namespacing-outside-of-the-yahoo-namespace/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 01:34:24 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Namespacing]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/08/28/namespacing-outside-of-the-yahoo-namespace/</guid>
		<description><![CDATA[YAHOO.namespace(). A lovely little utility function subject that I&#8217;ve written about before. If you&#8217;ve never heard of YAHOO.namespace or aren&#8217;t even familiar with namespacing, I&#8217;d read that article first. I&#8217;ll be honest, using the YAHOO namespace to store my own code makes my bunghole tighten just a little bit. What if I had written code [...]]]></description>
			<content:encoded><![CDATA[<p>YAHOO.namespace().  A lovely little utility function subject that <a href="http://www.zachleat.com/web/2007/08/09/yui-code-review-yahoonamespace/">I&#8217;ve written about before</a>.  If you&#8217;ve never heard of YAHOO.namespace or aren&#8217;t even familiar with namespacing, I&#8217;d read that article first.</p>
<p>I&#8217;ll be honest, using the YAHOO namespace to store my own code makes my bunghole tighten just a little bit.  What if I had written code stored under YAHOO.tool, which was unused prior to YUI 2.3.0?  What would I do now?  I&#8217;d have to rewrite my code, or never include any of the wonderful <code>YAHOO.tool.TestCase</code>, put together by <a href="http://www.nczonline.net/">Nicholas Zakas</a>.  As is traditional with most of my weblog posts, I try not to just complain about a problem without giving you a solution (but let&#8217;s be honest, only if it doesn&#8217;t take too much work).</p>
<p>Let&#8217;s rewrite the YAHOO.namespace function to work outside of the YAHOO Namespace, so we can do things like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'zachsWorld.partyTime'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
zachsWorld.<span style="color: #660066;">partyTime</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;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'Excellent.'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
zachsWorld.<span style="color: #660066;">partyTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// obviously would alert: Excellent.</span></pre></div></div>

<p>Here&#8217;s some code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #003366; font-weight: bold;">namespace</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> a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">,</span> o<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> d<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>a.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        d<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        o<span style="color: #339933;">=</span>window<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>d.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            o<span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Obviously this is just a modification of the YAHOO.namespace function.  I&#8217;d recommend putting this under your own namespace (I&#8217;m trying to put most of the code I write on this website under the Y2 namespace, but everyone should have their own parent namespace), like so (any namespaces you create using this function won&#8217;t use the parent namespace assigned here by default):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> Y2 <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> Y2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
Y2.<span style="color: #003366; font-weight: bold;">namespace</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: #009966; font-style: italic;">/* copy function contents from above. */</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But you can do whatever you want.  This is one of the functions that I think separates YUI from the other frameworks out there, giving an easy utility to organize your code.  This is something I think jQuery seriously lacks, noting from the code inside the many jQuery plugins contributed by end users.  Many jQuery contributors do not organize their code, putting multiple unnecessary top level functions into jQuery.fn as methods, or into the jQuery object itself as functions.  People whine about polluting the global namespace&#8230; I suppose it might be considered nitpickey to whine about the jQuery namespace.  Okay you whiney bastard, let&#8217;s help out and put this into jQuery!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// include jQuery first.</span>
jQuery.<span style="color: #003366; font-weight: bold;">namespace</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: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">,</span> o<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> d<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>a.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        d<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        o<span style="color: #339933;">=</span>window<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>d.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            o<span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Please note, this method does NOT work using jQuery methods with an element context, such as jQuery(&#8216;div&#8217;).myNamespace.myMethod().  Your element context won&#8217;t be carried through to myMethod().</p>
<p>However, you can use it for jQuery functions, such as this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// definition</span>
jQuery.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'jQuery.debug'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test1</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;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'test1 function'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test2</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;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'test2 function'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// usage</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test1</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">debug</span>.<span style="color: #660066;">test2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>For more information, you can read <a href="http://yuiblog.com/blog/2006/06/01/global-domination/">Global Domination, an article written by Douglas Crockford</a>, or <a href="http://docs.jquery.com/Plugins/Authoring">Best Practices for Writing jQuery plugins</a>.</p>
<p><b>Updated</b>: fixed some weird source parsing errors introduced by the code formatting plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/namespacing-outside-of-the-yahoo-namespace/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>YUI Code Review: YAHOO.namespace</title>
		<link>http://www.zachleat.com/web/yui-code-review-yahoonamespace/</link>
		<comments>http://www.zachleat.com/web/yui-code-review-yahoonamespace/#comments</comments>
		<pubDate>Fri, 10 Aug 2007 00:28:46 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Namespacing]]></category>
		<category><![CDATA[YUI]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/08/09/yui-code-review-yahoonamespace/</guid>
		<description><![CDATA[This is the first in a one+ part series of posts (the + is optional) reviewing the actual code contained in the YUI library. This series is not intended for advanced JavaScripters, so if you&#8217;re insulted by reading things you already know, you probably aren&#8217;t a very good student. YAHOO.namespace. This is a great little [...]]]></description>
			<content:encoded><![CDATA[<p><em>This is the first in a one+ part series of posts (the + is optional) reviewing the actual code contained in the YUI library.  This series is not intended for advanced JavaScripters, so if you&#8217;re insulted by reading things you already know, you probably aren&#8217;t a very good student.</em></p>
<p>YAHOO.namespace.  This is a great little utility function that gives you an easy way to encourage low coupling throughout your JavaScript code.  Divide your functions into functional units!  If you already know how to use this function, you can skip to the bottom to learn a few JavaScript tricks Yahoo has put in.  If not, keep reading!  Are you making a new package you want to put under the YAHOO namespace?  Just declare it in a string argument passed into the YAHOO.namespace function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This will create a YAHOO.myNamespace object that can be used many different ways.  You can assign a single function to it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">myNamespace</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: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
YAHOO.<span style="color: #660066;">myNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Or you can assign multiple functions to it (with private variables included) using the <a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">amazing Module Pattern</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #660066;">myNamespace</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: #003366; font-weight: bold;">var</span> myPrivateVariable<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
		myFirstFunction<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> myPrivateVariable<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		mySecondFunction<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;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> hisOrHerPrivateVariable <span style="color: #339933;">=</span> YAHOO.<span style="color: #660066;">myNamespace</span>.<span style="color: #660066;">myFirstFunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
YAHOO.<span style="color: #660066;">myNamespace</span>.<span style="color: #660066;">mySecondFunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Did you know that you can pass multiple arguments into YAHOO.namespace?  I&#8217;ve been using YUI all this time and didn&#8217;t know about this feature.  But the more I think about it, the more I doubt it&#8217;s usefulness.  When are you going to declare two unrelated namespaces adjacently in code?  For example, doing this is redundant in YUI:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace.myNestedNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The second call to YAHOO.namespace will reuse &#8216;myNamespace&#8217; if it exists, and create it if it doesn&#8217;t.  But the point here is that you can do something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myNamespace'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'myOtherNamespace'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>which will create YAHOO.myNamespace and YAHOO.myOtherNamespace, and return a reference to the last one created, in this case YAHOO.myOtherNamespace.</p>
<p>Here&#8217;s the code from this nice little function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">YAHOO.<span style="color: #003366; font-weight: bold;">namespace</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: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">=</span>arguments<span style="color: #339933;">,</span> o<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">,</span> d<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>a .<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        d<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        o<span style="color: #339933;">=</span>YAHOO<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// YAHOO is implied, so it is ignored if it is included</span>
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;YAHOO&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>d.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
            o<span style="color: #339933;">=</span>o<span style="color: #009900;">&#91;</span>d<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<ol>
<li><code>var a=arguments</code>: They&#8217;re iterating over the arguments passed into the function to declare multiple simultaneously.  Arguments is the variable passed into every function that you can use if you want to handle a variable number of arguments.  You can also declare a few arguments in the function( myArg ) and use the arguments variable if you want.</li>
<li><code>j=(d[0] == "YAHOO") ? 1 : 0</code> They reuse the YAHOO top level object if not explicitly included into the declaration.  Start the index at 1 if YAHOO was declared to skip defining it twice.</li>
<li><code>o[d[j]]=o[d[j]] || {};</code> They reuse existing namespaces if they have already been created.  The OR || declaration means that Javascript will use {} (an empty object) if o[d[j]] is undefined.</li>
<p></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/yui-code-review-yahoonamespace/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

