<?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: JavaScript patterns (dot com)</title>
	<atom:link href="http://www.phpied.com/javascript-patterns-dot-com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpied.com/javascript-patterns-dot-com/</link>
	<description>Stoyan&#039;s blog about &#60;a href=&#34;/category/xhtml&#34; class=&#34;tag-minor&#34;&#62;(x)html(5)&#60;/a&#62;, &#60;a href=&#34;/category/ajax&#34; class=&#34;tag-major&#34;&#62;ajax&#60;/a&#62;, &#60;a href=&#34;/category/bookmarklets&#34; class=&#34;tag-major&#34;&#62;bookmarklets&#60;/a&#62;, &#60;a href=&#34;/category/browsers&#34; class=&#34;tag-minor&#34;&#62;browsers&#60;/a&#62;, &#60;a href=&#34;/category/css&#34; class=&#34;tag-normal&#34;&#62;css&#60;/a&#62;, &#60;a href=&#34;/category/firebug&#34; class=&#34;tag-minor&#34;&#62;firebug&#60;/a&#62;, &#60;a href=&#34;/category/javascript&#34; class=&#34;tag-numero-uno&#34;&#62;javascript&#60;/a&#62;, &#60;a href=&#34;/category/json&#34; class=&#34;tag-normal&#34;&#62;json&#60;/a&#62;, &#60;a href=&#34;/category/mdb2&#34; class=&#34;tag-minor&#34;&#62;mdb2&#60;/a&#62;, &#60;a href=&#34;/category/mysql&#34; class=&#34;tag-normal&#34;&#62;mysql&#60;/a&#62;, &#60;a href=&#34;/category/pear&#34; class=&#34;tag-numero-uno&#34;&#62;pear&#60;/a&#62;, &#60;a href=&#34;/category/performance&#34; class=&#34;tag-major&#34;&#62;performance&#60;/a&#62;, &#60;a href=&#34;/category/php&#34; class=&#34;tag-numero-uno&#34;&#62;php&#60;/a&#62;, &#60;a href=&#34;/category/phpbb&#34; class=&#34;tag-major&#34;&#62;phpbb&#60;/a&#62;, &#60;a href=&#34;/category/tools&#34; class=&#34;tag-normal&#34;&#62;tools&#60;/a&#62;, &#60;a href=&#34;/category/yslow&#34; class=&#34;tag-minor&#34;&#62;yslow&#60;/a&#62;, &#60;a href=&#34;/category/yui&#34; class=&#34;tag-normal&#34;&#62;yui&#60;/a&#62;, &#60;a href=&#34;/category/writing&#34; class=&#34;tag-minor&#34;&#62;writing&#60;/a&#62;, &#60;a href=&#34;/category/music&#34; class=&#34;tag-major&#34;&#62;music&#60;/a&#62;,... &#60;a href=&#34;/category/life-and-everything&#34; class=&#34;tag-normal&#34;&#62;life and everything&#60;/a&#62;.</description>
	<lastBuildDate>Sat, 11 Feb 2012 14:07:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Stoyan</title>
		<link>http://www.phpied.com/javascript-patterns-dot-com/#comment-69401</link>
		<dc:creator>Stoyan</dc:creator>
		<pubDate>Wed, 18 Jun 2008 21:37:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/javascript-patterns-dot-com/#comment-69401</guid>
		<description>Hey Kunal,

I remember you, of course. 

The book is not published yet, but interestingly enough, it was announced just today on the publisher&#039;s website:
http://www.packtpub.com/object-oriented-javascript-applications-libraries/book

Best regards!</description>
		<content:encoded><![CDATA[<p>Hey Kunal,</p>
<p>I remember you, of course. </p>
<p>The book is not published yet, but interestingly enough, it was announced just today on the publisher&#8217;s website:<br />
<a href="http://www.packtpub.com/object-oriented-javascript-applications-libraries/book" rel="nofollow">http://www.packtpub.com/object-oriented-javascript-applications-libraries/book</a></p>
<p>Best regards!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kunal Cholera</title>
		<link>http://www.phpied.com/javascript-patterns-dot-com/#comment-69399</link>
		<dc:creator>Kunal Cholera</dc:creator>
		<pubDate>Wed, 18 Jun 2008 20:23:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/javascript-patterns-dot-com/#comment-69399</guid>
		<description>Hey Stoyan Stefanov,

I had a chance to interview with you for summer internship at Santa Monica Office.

You were talking about writing a book on object oriented javascript !! Whens it coming out ? I have a keen interest in JavaScript..</description>
		<content:encoded><![CDATA[<p>Hey Stoyan Stefanov,</p>
<p>I had a chance to interview with you for summer internship at Santa Monica Office.</p>
<p>You were talking about writing a book on object oriented javascript !! Whens it coming out ? I have a keen interest in JavaScript..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoyan</title>
		<link>http://www.phpied.com/javascript-patterns-dot-com/#comment-61921</link>
		<dc:creator>Stoyan</dc:creator>
		<pubDate>Fri, 17 Aug 2007 00:04:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/javascript-patterns-dot-com/#comment-61921</guid>
		<description>Ha! I figured out that I can use a method that keeps the instance secure. Check out Single2.1 ;)
http://www.jspatterns.com/index.php?title=Singleton2#Singleton_2.1</description>
		<content:encoded><![CDATA[<p>Ha! I figured out that I can use a method that keeps the instance secure. Check out Single2.1 <img src='http://www.phpied.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
<a href="http://www.jspatterns.com/index.php?title=Singleton2#Singleton_2.1" rel="nofollow">http://www.jspatterns.com/index.php?title=Singleton2#Singleton_2.1</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoyan</title>
		<link>http://www.phpied.com/javascript-patterns-dot-com/#comment-61915</link>
		<dc:creator>Stoyan</dc:creator>
		<pubDate>Wed, 15 Aug 2007 00:49:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/javascript-patterns-dot-com/#comment-61915</guid>
		<description>This is interesting you suggest. I liked my example because you get to keep the new Single() syntax and the class takes care of returning the same object.

But it&#039;s true that keeping the reference as a property of the constructor function makes it available for modification.

I&#039;ll play around you your idea of keeping the reference private but still be able to just say:
new Sungle(), new Single() and they both point to the same object.</description>
		<content:encoded><![CDATA[<p>This is interesting you suggest. I liked my example because you get to keep the new Single() syntax and the class takes care of returning the same object.</p>
<p>But it&#8217;s true that keeping the reference as a property of the constructor function makes it available for modification.</p>
<p>I&#8217;ll play around you your idea of keeping the reference private but still be able to just say:<br />
new Sungle(), new Single() and they both point to the same object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Foley</title>
		<link>http://www.phpied.com/javascript-patterns-dot-com/#comment-61896</link>
		<dc:creator>David Foley</dc:creator>
		<pubDate>Mon, 13 Aug 2007 00:09:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/javascript-patterns-dot-com/#comment-61896</guid>
		<description>Had a look at jspatterns.com -  glad to see someone providing a resource for applied javascript patterns! Had a quick glance through the site (I know its early days) and read over the Singleton discussions. Object literals as implementations of the Singleton pattern are fine, but there&#039;s something I&#039;d like to bring to your attention.

In Singleton2, the instance property lives on the constructor, and as such is  externally modifiable which breaks encapsulation. If you&#039;re interested in more detail, email me, but for the moment, you might want to consider the following:
&lt;pre style=&quot;font-weight: normal&quot;&gt;

/**
 * toSingleton, transforms javascript classes into singletons
 * @copyright David Foley 2007
 * free as in beer!
 */

function MyClass ()
{
	var _value = null;
	this.setValue = function (value) {
		_value = value;
	};
	this.getValue = function () {
		return _value;
	};	 
};


/**
 *	@param {Function} Class, the class to transform into a singleton
 *@return {Object} an object with one method, getInstance, which returns an instance of Class
 */

function toSingleton (Class) 
{
	// return the results of an anonymours function
	return (function(){
		// variable instance exists in this closure 
		// private and cannot be modified externally
		var  instance = null;
		// the following object literal is returned
		// as the final result of the toSingleton transformation
		// it can access the variable &#039;instance&#039;, but
		// nothing else can, in keeping with priniciple
		// of encapsulation
		return {
			getInstance: function()
			{
				if( instance == null) instance = new Class();
				return instance;
			}
		};
	})();
};

// overwrite MyClass with the result of the toSingleton transformation
MyClass = toSingleton(MyClass);

// show it works
MySingletonReference = MyClass.getInstance();
MyClass.getInstance().setValue(&quot;1&quot;);
alert(MySingletonReference.getValue());
MySingletonReference.setValue(&quot;2&quot;);
alert(MyClass.getInstance().getValue());
alert(MySingletonReference.getValue() == MyClass.getInstance().getValue());
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Had a look at jspatterns.com &#8211;  glad to see someone providing a resource for applied javascript patterns! Had a quick glance through the site (I know its early days) and read over the Singleton discussions. Object literals as implementations of the Singleton pattern are fine, but there&#8217;s something I&#8217;d like to bring to your attention.</p>
<p>In Singleton2, the instance property lives on the constructor, and as such is  externally modifiable which breaks encapsulation. If you&#8217;re interested in more detail, email me, but for the moment, you might want to consider the following:</p>
<pre style="font-weight: normal">

/**
 * toSingleton, transforms javascript classes into singletons
 * @copyright David Foley 2007
 * free as in beer!
 */

function MyClass ()
{
	var _value = null;
	this.setValue = function (value) {
		_value = value;
	};
	this.getValue = function () {
		return _value;
	};
};

/**
 *	@param {Function} Class, the class to transform into a singleton
 *@return {Object} an object with one method, getInstance, which returns an instance of Class
 */

function toSingleton (Class)
{
	// return the results of an anonymours function
	return (function(){
		// variable instance exists in this closure
		// private and cannot be modified externally
		var  instance = null;
		// the following object literal is returned
		// as the final result of the toSingleton transformation
		// it can access the variable 'instance', but
		// nothing else can, in keeping with priniciple
		// of encapsulation
		return {
			getInstance: function()
			{
				if( instance == null) instance = new Class();
				return instance;
			}
		};
	})();
};

// overwrite MyClass with the result of the toSingleton transformation
MyClass = toSingleton(MyClass);

// show it works
MySingletonReference = MyClass.getInstance();
MyClass.getInstance().setValue("1");
alert(MySingletonReference.getValue());
MySingletonReference.setValue("2");
alert(MyClass.getInstance().getValue());
alert(MySingletonReference.getValue() == MyClass.getInstance().getValue());
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>

