<?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: Global Domination, Part Two</title>
	<atom:link href="http://www.yuiblog.com/blog/index.php/2008/04/16/global-domination-part-two/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/</link>
	<description>The official blog of the YUI Project.</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:46:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Douglas Crockford</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-597879</link>
		<dc:creator>Douglas Crockford</dc:creator>
		<pubDate>Tue, 29 Mar 2011 19:01:18 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-597879</guid>
		<description>I recommend using only the function form of strict mode declaration. Zach&#039;s comment only applies to the file form.</description>
		<content:encoded><![CDATA[<p>I recommend using only the function form of strict mode declaration. Zach&#8217;s comment only applies to the file form.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach Leatherman</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-597878</link>
		<dc:creator>Zach Leatherman</dc:creator>
		<pubDate>Tue, 29 Mar 2011 18:26:56 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-597878</guid>
		<description>Don&#039;t use the method described in the above article, if you know what&#039;s good for you. Your code will break in ES-5 strict mode.

&lt;q&gt;Since undeclared assignments are such a misleading part of the language, ECMAScript 5 — newest version of ECMAScript — specifies that when they occur in a strict mode, a ReferenceError should be thrown. This makes for more robust code with less chance for unexpected errors. And since strict mode is more or less a future direction of the language, it makes sense to avoid undeclared assignments as if they never existed.&lt;/q&gt;

http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/</description>
		<content:encoded><![CDATA[<p>Don&#8217;t use the method described in the above article, if you know what&#8217;s good for you. Your code will break in ES-5 strict mode.</p>
<p><q>Since undeclared assignments are such a misleading part of the language, ECMAScript 5 — newest version of ECMAScript — specifies that when they occur in a strict mode, a ReferenceError should be thrown. This makes for more robust code with less chance for unexpected errors. And since strict mode is more or less a future direction of the language, it makes sense to avoid undeclared assignments as if they never existed.</q></p>
<p><a href="http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/" rel="nofollow">http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jay in Oregon</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-592749</link>
		<dc:creator>Jay in Oregon</dc:creator>
		<pubDate>Mon, 12 Jul 2010 18:57:36 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-592749</guid>
		<description>&lt;cite&gt;But the thing that finally convinced me that the first form is the least worst is that IE gets the second form wrong, so that responsibly adaptive programs fail&lt;/cite&gt;

I haven&#039;t been able to find any information on how IE gets the second form wrong.

Personally, I&#039;ve been using:
&lt;code&gt;
var fooObj;
if (fooObj === undefined) {
	fooObj = {};
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p><cite>But the thing that finally convinced me that the first form is the least worst is that IE gets the second form wrong, so that responsibly adaptive programs fail</cite></p>
<p>I haven&#8217;t been able to find any information on how IE gets the second form wrong.</p>
<p>Personally, I&#8217;ve been using:<br />
<code><br />
var fooObj;<br />
if (fooObj === undefined) {<br />
	fooObj = {};<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Diego Perini</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-587927</link>
		<dc:creator>Diego Perini</dc:creator>
		<pubDate>Sat, 30 Jan 2010 00:48:44 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-587927</guid>
		<description>another form that I usually prefer is:

    this.pity &#124;&#124; (this.pity = {});

the reason is it avoids an extra &quot;same value&quot; assignment if that global already exist and I do the same in functions for passed parameters:

    function doSomething (a) {
      a &#124;&#124; (a = &quot;defaultValue&quot;);
    }

good to spread the voice whatever the correct...</description>
		<content:encoded><![CDATA[<p>another form that I usually prefer is:</p>
<p>    this.pity || (this.pity = {});</p>
<p>the reason is it avoids an extra &#8220;same value&#8221; assignment if that global already exist and I do the same in functions for passed parameters:</p>
<p>    function doSomething (a) {<br />
      a || (a = &#8220;defaultValue&#8221;);<br />
    }</p>
<p>good to spread the voice whatever the correct&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bernie Margolis</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-520585</link>
		<dc:creator>Bernie Margolis</dc:creator>
		<pubDate>Wed, 19 Nov 2008 23:24:00 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-520585</guid>
		<description>I like how the ExtJS library handles this.  They abstract developers away from the problem by providing a utility to create &#039;namespaces.&#039;  I don&#039;t know how exactly they are doing it under the covers, but I know that Douglas Crockford&#039;s javascript site is a heavy influence on their development, so I wouldn&#039;t be surprised to find that they use one of the forms presented above.  As a developer, though, all I have to do is this:
  Ext.namespace(&#039;pity&#039;);
or this shorter form:
  Ext.ns(&#039;pity&#039;);
I can even declare multiple levels on a single line:
  Ext.ns(&#039;pity&#039;,&#039;pity.util&#039;, &#039;pity.util.text&#039;);</description>
		<content:encoded><![CDATA[<p>I like how the ExtJS library handles this.  They abstract developers away from the problem by providing a utility to create &#8216;namespaces.&#8217;  I don&#8217;t know how exactly they are doing it under the covers, but I know that Douglas Crockford&#8217;s javascript site is a heavy influence on their development, so I wouldn&#8217;t be surprised to find that they use one of the forms presented above.  As a developer, though, all I have to do is this:<br />
  Ext.namespace(&#8216;pity&#8217;);<br />
or this shorter form:<br />
  Ext.ns(&#8216;pity&#8217;);<br />
I can even declare multiple levels on a single line:<br />
  Ext.ns(&#8216;pity&#8217;,'pity.util&#8217;, &#8216;pity.util.text&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: scriptNode / My New Coding Habits</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-436044</link>
		<dc:creator>scriptNode / My New Coding Habits</dc:creator>
		<pubDate>Sun, 03 Aug 2008 05:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-436044</guid>
		<description>[...] be lying if I said I wasn&#039;t externally influenced on this one. Douglas Crockford has a lot of great recommendations, and this is one I tend to agree [...]</description>
		<content:encoded><![CDATA[<p>[...] be lying if I said I wasn&#8217;t externally influenced on this one. Douglas Crockford has a lot of great recommendations, and this is one I tend to agree [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frode Danielsen</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-365059</link>
		<dc:creator>Frode Danielsen</dc:creator>
		<pubDate>Fri, 02 May 2008 02:30:08 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-365059</guid>
		<description>The &quot;var pity = this.pity &#124;&#124; {}&quot; and it&#039;s variants has become quite popular in recent Javascript libraries, and I like it myself. You&#039;ll have to give in to the assumption that you use it in places where booleans are not values you expect.

One of the most useful cases for me would be as a default value for function parameters. Consider:

function doSomething (a) {
	a = a &#124;&#124; &#039;defaultValue&#039;;
}

If the variable &#039;a&#039; is undefined here, it will get a default value instead, making the variable &#039;a&#039; useful to the rest of the function.

Though if you prefer, I guess it could be written as:

function doSomething (a) {
	a = (a !== undefined ? a : &#039;defaultValue&#039;);
}</description>
		<content:encoded><![CDATA[<p>The &#8220;var pity = this.pity || {}&#8221; and it&#8217;s variants has become quite popular in recent Javascript libraries, and I like it myself. You&#8217;ll have to give in to the assumption that you use it in places where booleans are not values you expect.</p>
<p>One of the most useful cases for me would be as a default value for function parameters. Consider:</p>
<p>function doSomething (a) {<br />
	a = a || &#8216;defaultValue&#8217;;<br />
}</p>
<p>If the variable &#8216;a&#8217; is undefined here, it will get a default value instead, making the variable &#8216;a&#8217; useful to the rest of the function.</p>
<p>Though if you prefer, I guess it could be written as:</p>
<p>function doSomething (a) {<br />
	a = (a !== undefined ? a : &#8216;defaultValue&#8217;);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zach Leatherman</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-355852</link>
		<dc:creator>Zach Leatherman</dc:creator>
		<pubDate>Tue, 22 Apr 2008 03:07:49 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-355852</guid>
		<description>I would think that it is common knowledge to check &lt;code&gt;typeof pity === &#039;undefined&#039;&lt;/code&gt;, instead of using a construct like &lt;code&gt;var pity = this.pity &#124;&#124; {};&lt;/code&gt;, especially assuming that the code in question is the byproduct of a reasonably adaptive program.

If you assume that the web developer audiences that program in ignorance of the language and the readership of this blog (or the readership of any JavaScript blog author who adopts this method) are mutually exclusive, then  one might trend towards agreeing your third form is appropriate.

But, seeing that most developers &quot;learn&quot; from copy and paste, it would seem that the second form would be safer, if for no other reason than to prevent those abominable globals we all abhor.</description>
		<content:encoded><![CDATA[<p>I would think that it is common knowledge to check <code>typeof pity === 'undefined'</code>, instead of using a construct like <code>var pity = this.pity || {};</code>, especially assuming that the code in question is the byproduct of a reasonably adaptive program.</p>
<p>If you assume that the web developer audiences that program in ignorance of the language and the readership of this blog (or the readership of any JavaScript blog author who adopts this method) are mutually exclusive, then  one might trend towards agreeing your third form is appropriate.</p>
<p>But, seeing that most developers &#8220;learn&#8221; from copy and paste, it would seem that the second form would be safer, if for no other reason than to prevent those abominable globals we all abhor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Administrator</title>
		<link>http://www.yuiblog.com/blog/2008/04/16/global-domination-part-two/comment-page-1/#comment-355045</link>
		<dc:creator>Administrator</dc:creator>
		<pubDate>Mon, 21 Apr 2008 11:22:12 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2008/04/16/global-domination-part-two/#comment-355045</guid>
		<description>Testing the comment system, which was down for a while there. Everything seems back to normal, though, so give it a go!</description>
		<content:encoded><![CDATA[<p>Testing the comment system, which was down for a while there. Everything seems back to normal, though, so give it a go!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

