<?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>David Calhoun&#039;s Blog &#187; OO</title>
	<atom:link href="http://davidbcalhoun.com/tag/oo/feed" rel="self" type="application/rss+xml" />
	<link>http://davidbcalhoun.com</link>
	<description>Just another blog</description>
	<lastBuildDate>Mon, 07 May 2012 02:06:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>JavaScript Tidbit: Shorthand Object Instantiation</title>
		<link>http://davidbcalhoun.com/2009/javascript-tidbit-shorthand-object-instantiation</link>
		<comments>http://davidbcalhoun.com/2009/javascript-tidbit-shorthand-object-instantiation#comments</comments>
		<pubDate>Mon, 14 Sep 2009 07:26:23 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[john resig]]></category>
		<category><![CDATA[OO]]></category>

		<guid isPermaLink="false">http://davidbcalhoun.com/?p=10</guid>
		<description><![CDATA[The skinny: here&#8217;s a neat little trick to reduce the amount of code users have to type to instantiate objects: function jQuery(str, con){ if ( window == this ) return new jQuery(str, con); // ... } new jQuery("#foo"); // this is now equivalent... jQuery("#foo"); // ...to this! Explanation: when jQuery(&#8220;#foo&#8221;) is typed, the function first [...]]]></description>
			<content:encoded><![CDATA[<p>The skinny: here&#8217;s a neat little trick to reduce the amount of code users have to type to instantiate objects:</p>
<pre name="code" class="js">function jQuery(str, con){
    if ( window == this )
        return new jQuery(str, con);
    // ...
}

new jQuery("#foo"); // this is now equivalent...
jQuery("#foo");     // ...to this!</pre>
<p>Explanation: when jQuery(&#8220;#foo&#8221;) is typed, the function first determines if the context in which it&#8217;s being called is the global object (window).  If it is, it returns an instantiation of itself.  When it&#8217;s instantiated, the context in which it&#8217;s being called is inside its own function, and NOT within the global object (window), thus it bypasses our little instantiation trick and moves on to execute any remaining code in the function.</p>
<p>From John Resig&#8217;s <a href="http://www.youtube.com/watch?v=0LKDImgRfrg#t=32m2s">Best Practices in Javascript Library Design</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidbcalhoun.com/2009/javascript-tidbit-shorthand-object-instantiation/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

