<?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 widget approaches: Singleton vs Prototype</title>
	<atom:link href="http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/</link>
	<description>web-development</description>
	<lastBuildDate>Wed, 14 Jul 2010 16:05:17 +0000</lastBuildDate>
	
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Amy Blankenship</title>
		<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/comment-page-1/#comment-30313</link>
		<dc:creator>Amy Blankenship</dc:creator>
		<pubDate>Sat, 24 Apr 2010 13:37:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.selfcontained.us/?p=69#comment-30313</guid>
		<description>As an ActionScript developer, I find it hard to consider this a &quot;real&quot; Singleton approach, in that all you&#039;ve really done is create one instance by using an anonymous function.  This is nothing you couldn&#039;t do by simply only creating one instance any other way, but by doing it this way, you make code reuse more difficult.

A &quot;true&quot; Singleton approach would already initialized object, if it exists, or a new object, if it doesn&#039;t.  In the absense of AS3 style static variables, if you can dynamically add a property to the document, you could potentially use it to store a reference to the Singleton and then return that or a new object based on whether the object exists or not.  It might look something like this:

function Singleton() {
  if (document._myunlikelySingletonName) {
       return document._myunlikelySingletonName;
  } else {
       var obj =  new Object();
       document._myunlikelySingletonName = obj;
       return obj;
}

Of course, this presumes a slightly different purpose for wanting a Singleton--to make sure that everything referring to any instance of the Singleton is referring to the same thing.  But like I said, you don&#039;t need Singleton for the purpose of only ever having one instance created--you just create one instance!</description>
		<content:encoded><![CDATA[<p>As an ActionScript developer, I find it hard to consider this a &#8220;real&#8221; Singleton approach, in that all you&#8217;ve really done is create one instance by using an anonymous function.  This is nothing you couldn&#8217;t do by simply only creating one instance any other way, but by doing it this way, you make code reuse more difficult.</p>
<p>A &#8220;true&#8221; Singleton approach would already initialized object, if it exists, or a new object, if it doesn&#8217;t.  In the absense of AS3 style static variables, if you can dynamically add a property to the document, you could potentially use it to store a reference to the Singleton and then return that or a new object based on whether the object exists or not.  It might look something like this:</p>
<p>function Singleton() {<br />
  if (document._myunlikelySingletonName) {<br />
       return document._myunlikelySingletonName;<br />
  } else {<br />
       var obj =  new Object();<br />
       document._myunlikelySingletonName = obj;<br />
       return obj;<br />
}</p>
<p>Of course, this presumes a slightly different purpose for wanting a Singleton&#8211;to make sure that everything referring to any instance of the Singleton is referring to the same thing.  But like I said, you don&#8217;t need Singleton for the purpose of only ever having one instance created&#8211;you just create one instance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alexwebmaster</title>
		<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/comment-page-1/#comment-17889</link>
		<dc:creator>Alexwebmaster</dc:creator>
		<pubDate>Tue, 03 Mar 2009 10:51:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.selfcontained.us/?p=69#comment-17889</guid>
		<description>Hello webmaster 
I would like to share with you a link to your site 
write me here preonrelt@mail.ru</description>
		<content:encoded><![CDATA[<p>Hello webmaster<br />
I would like to share with you a link to your site<br />
write me here <a href="mailto:preonrelt@mail.ru">preonrelt@mail.ru</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Metablocks &#124; Widget Development Best Practices - Widget Developers - Widget, Gadget and Social Media App Design and Development</title>
		<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/comment-page-1/#comment-16168</link>
		<dc:creator>Metablocks &#124; Widget Development Best Practices - Widget Developers - Widget, Gadget and Social Media App Design and Development</dc:creator>
		<pubDate>Wed, 14 Jan 2009 16:39:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.selfcontained.us/?p=69#comment-16168</guid>
		<description>[...] Javascript Widget Approaches [...]</description>
		<content:encoded><![CDATA[<p>[...] Javascript Widget Approaches [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: brad</title>
		<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/comment-page-1/#comment-15850</link>
		<dc:creator>brad</dc:creator>
		<pubDate>Wed, 07 Jan 2009 16:33:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.selfcontained.us/?p=69#comment-15850</guid>
		<description>Correct, having that many &#039;widgets&#039; on a page is definitely out of the norm, and in such a case you would definitely need a different approach to managing your event listeners in general.</description>
		<content:encoded><![CDATA[<p>Correct, having that many &#8216;widgets&#8217; on a page is definitely out of the norm, and in such a case you would definitely need a different approach to managing your event listeners in general.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: meeech</title>
		<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/comment-page-1/#comment-15849</link>
		<dc:creator>meeech</dc:creator>
		<pubDate>Wed, 07 Jan 2009 16:16:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.selfcontained.us/?p=69#comment-15849</guid>
		<description>re: singleton, click events,  This ‘can’ be time consuming with a large number of elements (1000+).

I think if you find yourself in a case where you have an abnormally high number of calendars on a page, to the point where attaching listeners is affecting performance, you could always just change the clickhandling to listen to the parent container, and trigger from there.</description>
		<content:encoded><![CDATA[<p>re: singleton, click events,  This ‘can’ be time consuming with a large number of elements (1000+).</p>
<p>I think if you find yourself in a case where you have an abnormally high number of calendars on a page, to the point where attaching listeners is affecting performance, you could always just change the clickhandling to listen to the parent container, and trigger from there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: In the Wild for January 6, 2009 &#187; Yahoo! User Interface Blog</title>
		<link>http://www.selfcontained.us/2008/12/23/javascript-widget-approaches-singleton-vs-prototype/comment-page-1/#comment-15797</link>
		<dc:creator>In the Wild for January 6, 2009 &#187; Yahoo! User Interface Blog</dc:creator>
		<pubDate>Tue, 06 Jan 2009 21:10:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.selfcontained.us/?p=69#comment-15797</guid>
		<description>[...] Patterns for Widget Development: Brad Harris has a tutorial up on his selfcontained blog treating the subject of widget development patterns for JavaScript: &#8220;Recently I’ve been doing some work setting up some standard javascript widgets for a web application I am working on. By widget, I’m referring to items such as javascript date pickers, tooltips, autocomplete inputs, etc. I’m building on top of YUI for this approach, but the principles I’d like to discuss are applicable to any library. YUI provides a fantastic javascript library, and a collection of widgets right out of the box. More than likely, as you add them to your application, you’ll want to wrap or extend them in your own javascript implementations to get them functioning as desired. To accomplish this, I typically have taken one of two approaches, and these are the topic I’d like to cover. To provide a working example, I’ll use a simple wrapper for a YUI Calendar widget that is linked to a text input, and opens by clicking a calendar icon.&#8221;&#160; Check out his post for the full deep dive on the subject. [...]</description>
		<content:encoded><![CDATA[<p>[...] Patterns for Widget Development: Brad Harris has a tutorial up on his selfcontained blog treating the subject of widget development patterns for JavaScript: &#8220;Recently I’ve been doing some work setting up some standard javascript widgets for a web application I am working on. By widget, I’m referring to items such as javascript date pickers, tooltips, autocomplete inputs, etc. I’m building on top of YUI for this approach, but the principles I’d like to discuss are applicable to any library. YUI provides a fantastic javascript library, and a collection of widgets right out of the box. More than likely, as you add them to your application, you’ll want to wrap or extend them in your own javascript implementations to get them functioning as desired. To accomplish this, I typically have taken one of two approaches, and these are the topic I’d like to cover. To provide a working example, I’ll use a simple wrapper for a YUI Calendar widget that is linked to a text input, and opens by clicking a calendar icon.&#8221;&nbsp; Check out his post for the full deep dive on the subject. [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>
