<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
	>
<channel>
	<title>Comments on: Namespace Function</title>
	<atom:link href="http://mattsnider.com/languages/javascript/namespace-function/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattsnider.com/languages/javascript/namespace-function/</link>
	<description>Understanding JavaScript and Frameworks</description>
	<pubDate>Tue, 06 Jan 2009 06:14:12 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Karl Krukow</title>
		<link>http://mattsnider.com/languages/javascript/namespace-function/comment-page-1/#comment-18274</link>
		<dc:creator>Karl Krukow</dc:creator>
		<pubDate>Wed, 09 Jul 2008 18:28:42 +0000</pubDate>
		<guid isPermaLink="false">http://mattsnider.com/languages/javascript/namespace-function/#comment-18274</guid>
		<description>NP, I know exactly what you mean ;-)</description>
		<content:encoded><![CDATA[<p>NP, I know exactly what you mean <img src='http://mattsnider.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Snider</title>
		<link>http://mattsnider.com/languages/javascript/namespace-function/comment-page-1/#comment-18273</link>
		<dc:creator>Matt Snider</dc:creator>
		<pubDate>Wed, 09 Jul 2008 17:56:45 +0000</pubDate>
		<guid isPermaLink="false">http://mattsnider.com/languages/javascript/namespace-function/#comment-18273</guid>
		<description>Karl,

Good catch and thanks for the link. I've updated the last example. 

This is why I should not write blog articles in the middle of the night ^_^.</description>
		<content:encoded><![CDATA[<p>Karl,</p>
<p>Good catch and thanks for the link. I&#8217;ve updated the last example. </p>
<p>This is why I should not write blog articles in the middle of the night ^_^.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl Krukow</title>
		<link>http://mattsnider.com/languages/javascript/namespace-function/comment-page-1/#comment-18271</link>
		<dc:creator>Karl Krukow</dc:creator>
		<pubDate>Wed, 09 Jul 2008 17:39:15 +0000</pubDate>
		<guid isPermaLink="false">http://mattsnider.com/languages/javascript/namespace-function/#comment-18271</guid>
		<description>Hello Matt,

I have a couple of points. First the assignment:

object_mes_namespace('Widget.ImagePopout') = function(bd, src, emap) {
//...
};

Doesn't work as the left-hand side of the assignment is an expression. Did you mean:

object_mes_namespace('Widget').ImagePopout = function(bd, src, emap) {
//...
};


Secondly, I've written a somewhat long entry about &lt;a href="http://higher-order.blogspot.com/2008/02/designing-clientserver-web-applications.html" rel="nofollow"&gt;namespacing&lt;/a&gt;.  It allows for more general form of namespace declarations, and it has a complementary function 'using' which neatly brings a namespace into scope. Let me know what you think.

/Karl</description>
		<content:encoded><![CDATA[<p>Hello Matt,</p>
<p>I have a couple of points. First the assignment:</p>
<p>object_mes_namespace(&#8217;Widget.ImagePopout&#8217;) = function(bd, src, emap) {<br />
//&#8230;<br />
};</p>
<p>Doesn&#8217;t work as the left-hand side of the assignment is an expression. Did you mean:</p>
<p>object_mes_namespace(&#8217;Widget&#8217;).ImagePopout = function(bd, src, emap) {<br />
//&#8230;<br />
};</p>
<p>Secondly, I&#8217;ve written a somewhat long entry about <a href="http://higher-order.blogspot.com/2008/02/designing-clientserver-web-applications.html" rel="nofollow">namespacing</a>.  It allows for more general form of namespace declarations, and it has a complementary function &#8216;using&#8217; which neatly brings a namespace into scope. Let me know what you think.</p>
<p>/Karl</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric Gelinas</title>
		<link>http://mattsnider.com/languages/javascript/namespace-function/comment-page-1/#comment-18270</link>
		<dc:creator>Eric Gelinas</dc:creator>
		<pubDate>Wed, 09 Jul 2008 17:03:51 +0000</pubDate>
		<guid isPermaLink="false">http://mattsnider.com/languages/javascript/namespace-function/#comment-18270</guid>
		<description>I use this functionality on my site and I did not want my namespace to be "YAHOO.SP", i wanted it to just be "SP". I am surprised that YUI does not just let you create a namespace in the window object as an option.</description>
		<content:encoded><![CDATA[<p>I use this functionality on my site and I did not want my namespace to be &#8220;YAHOO.SP&#8221;, i wanted it to just be &#8220;SP&#8221;. I am surprised that YUI does not just let you create a namespace in the window object as an option.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Snider</title>
		<link>http://mattsnider.com/languages/javascript/namespace-function/comment-page-1/#comment-18266</link>
		<dc:creator>Matt Snider</dc:creator>
		<pubDate>Wed, 09 Jul 2008 15:44:59 +0000</pubDate>
		<guid isPermaLink="false">http://mattsnider.com/languages/javascript/namespace-function/#comment-18266</guid>
		<description>MillsJROSS,

My initial thoughts were exactly that. You can modify the method by adding the following after name = tok[j]:

if (o[name] &#038;&#038; j === tok.length - 1) {
throw("Your Exception Here");
}

However, after playing with the function a bit, I found myself most often using it at the beginning of a JavaScript file to ensure that the namespace I wanted to attach the new object to existed. So, if I wanted to attach a 'Dom' in one file and an 'Event' package in another file to 'Core.Util', then I called my function with 'Core.Util', in both files.

I think sometimes you don't want to throw an error, if the namespace exists, as with 'Core.Util', but other you do. For example if I called the namespace function for 'Core.Util.Event', as I would be overriding the event object.

You could therefore, pass in as the last object to the namespace function a boolean, 'throwErrorOnExistance', which would equal:

throwErrorOnExistance = isType(a[a.length-1], 'boolean') &#038;&#038; a[a.length-1];

and modify the error if statement to be:

if (throwErrorOnExistance &#038;&#038; o[name] &#038;&#038; j === tok.length - 1) {
throw("Your Exception Here");
}</description>
		<content:encoded><![CDATA[<p>MillsJROSS,</p>
<p>My initial thoughts were exactly that. You can modify the method by adding the following after name = tok[j]:</p>
<p>if (o[name] &#038;&#038; j === tok.length - 1) {<br />
throw(&#8221;Your Exception Here&#8221;);<br />
}</p>
<p>However, after playing with the function a bit, I found myself most often using it at the beginning of a JavaScript file to ensure that the namespace I wanted to attach the new object to existed. So, if I wanted to attach a &#8216;Dom&#8217; in one file and an &#8216;Event&#8217; package in another file to &#8216;Core.Util&#8217;, then I called my function with &#8216;Core.Util&#8217;, in both files.</p>
<p>I think sometimes you don&#8217;t want to throw an error, if the namespace exists, as with &#8216;Core.Util&#8217;, but other you do. For example if I called the namespace function for &#8216;Core.Util.Event&#8217;, as I would be overriding the event object.</p>
<p>You could therefore, pass in as the last object to the namespace function a boolean, &#8216;throwErrorOnExistance&#8217;, which would equal:</p>
<p>throwErrorOnExistance = isType(a[a.length-1], &#8216;boolean&#8217;) &#038;&#038; a[a.length-1];</p>
<p>and modify the error if statement to be:</p>
<p>if (throwErrorOnExistance &#038;&#038; o[name] &#038;&#038; j === tok.length - 1) {<br />
throw(&#8221;Your Exception Here&#8221;);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MillsJROSS</title>
		<link>http://mattsnider.com/languages/javascript/namespace-function/comment-page-1/#comment-18262</link>
		<dc:creator>MillsJROSS</dc:creator>
		<pubDate>Wed, 09 Jul 2008 13:30:14 +0000</pubDate>
		<guid isPermaLink="false">http://mattsnider.com/languages/javascript/namespace-function/#comment-18262</guid>
		<description>I'm not sure I quite understand the point of the namespace function. That said, I understand what it does. But I have a few problems with it. 

I don't like how it returns the namespace object. This allows me to write code like object_mes_namespace( "x" ) = 3; Which to me is the equivalent of x = 3; So even if x had existed before, it doesn't really matter, since it exists after the initialization anyway. There's more code to create a simple assignment. 

I understand the problem that arises, if say I want to access x.attr and x is undefined. This function ensures that x exists. I also understand that this function allows you to create objects in a succinct style. I think that this function would be more useful, though, if when you come across a collision there is some sort of warning or error that occurs.

I think this might be just an error, but shouldn't the o object be assigned back to the window object every time you iterate through the functions arguments? Also, if try to build on top of an attribute that's a literal and not an object, this function fails. Ex. x = 3; object_mes_namespace( "x.attr" ); Should fail.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not sure I quite understand the point of the namespace function. That said, I understand what it does. But I have a few problems with it. </p>
<p>I don&#8217;t like how it returns the namespace object. This allows me to write code like object_mes_namespace( &#8220;x&#8221; ) = 3; Which to me is the equivalent of x = 3; So even if x had existed before, it doesn&#8217;t really matter, since it exists after the initialization anyway. There&#8217;s more code to create a simple assignment. </p>
<p>I understand the problem that arises, if say I want to access x.attr and x is undefined. This function ensures that x exists. I also understand that this function allows you to create objects in a succinct style. I think that this function would be more useful, though, if when you come across a collision there is some sort of warning or error that occurs.</p>
<p>I think this might be just an error, but shouldn&#8217;t the o object be assigned back to the window object every time you iterate through the functions arguments? Also, if try to build on top of an attribute that&#8217;s a literal and not an object, this function fails. Ex. x = 3; object_mes_namespace( &#8220;x.attr&#8221; ); Should fail.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
