<?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>UnearthedMedia&#187; event</title>
	<atom:link href="http://unearthedmedia.com/tag/event/feed/" rel="self" type="application/rss+xml" />
	<link>http://unearthedmedia.com</link>
	<description>Business &#38; Technology</description>
	<lastBuildDate>Thu, 15 Apr 2010 18:46:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Singleton Theory with javascript and prototype</title>
		<link>http://unearthedmedia.com/2010/02/02/singleton-theory-with-javascript-and-prototype/</link>
		<comments>http://unearthedmedia.com/2010/02/02/singleton-theory-with-javascript-and-prototype/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 14:42:22 +0000</pubDate>
		<dc:creator>Kevin Harris</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[prototypejs]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[prototype javascript]]></category>
		<category><![CDATA[singleton theory]]></category>

		<guid isPermaLink="false">http://unearthedmedia.com/?p=101</guid>
		<description><![CDATA[I was searching for a way in javascript to handle classes dispatching events and listening for events. Generally javascript only has event methods for elements and not objects. Then I stumbbled onto http://www.truerwords.net where he has developed some event classes to mix-in to your own objects that give them the ability to listen and dispatch [...]]]></description>
			<content:encoded><![CDATA[<p>I was searching for a way in javascript to handle classes dispatching events and listening for events. Generally javascript only has event methods for elements and not objects. Then I stumbbled onto<span id="more-101"></span> <a href="http://www.truerwords.net/articles/web-tech/custom_events.html" target="_blank">http://www.truerwords.net</a> where he has developed some event classes to mix-in to your own objects that give them the ability to listen and dispatch events.  You must be using the <a title="prototype javascript library" href="http://www.prototypejs.org/" target="_blank">prototype javascript library</a> for these to work as that is what they were wrote with as well. Its pretty straight forward to use. Basically you include the event  js file  <code>&lt;script src="js/Events/event_mixins.js"&gt;&lt;/script&gt;</code> after this you will setup your classes as such</p>
<pre>
<pre class="brush: javascript">
var classObj= Class.create();

Object.extend(classObj.prototype, {

     events: [&#039;communicationTab&#039;, &#039;generalTab&#039;, &#039;scheduleTab&#039;, &#039;billingTab&#039;, &#039;financialAidTab&#039;, &#039;repositoryTab&#039;, &#039;sendEmail&#039;],//events fire from this class

     initialize: function() {
          //add listeners for this object
          this.listenForEvent( classListeningForEventFrom, &#039;loadData&#039;, true );
     },
      //this makes the class able to dispatch events
      onLoadData: function(evt) {}
});

//this makes the class able to listen for events Object.extend( classObj.prototype, , Event.Listener );
Object.extend( classObj.prototype, , Event.Publisher );
//To dispatch an event from this class its rather simple. All events that this class can dispatch should be set in your events array (more about this later).
this.dispatchEvent(&#039;sendEmail&#039;, {emailTo:me@here.com});
</pre>
<p>the second parameter in the dispatchEvent is data you want to pass to the receiving listener.  For a class to be a listener you must put the listenForEvent on the object. This does not have to be in the constructor but if the class is always listening for these events I would recommend putting it. By default the listener class will try to call a method in the listening class the same name as the event being listened for except it adds &#8220;on&#8221; to the event. So if you listening for the event &#8220;loadData&#8221; then your method in the class should be &#8220;onLoadData&#8221;  This is a fantastic approach to the issue with javascript and events. I don&#8217;t know why other libraries don&#8217;t incorporate something like this for their events. If you want to have a global listener so you don&#8217;t have to specify a specific class that your class is listening for I highly recommend looking at the Event Broker he has wrote.</p>
<p><br/><br/><script type="text/javascript"><!--
google_ad_client = "pub-9330786219612313";
/* post ads at bottom */
google_ad_slot = "4246337469";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://unearthedmedia.com/2010/02/02/singleton-theory-with-javascript-and-prototype/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
