<?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>Blog - ShiftEleven &#187; oop</title>
	<atom:link href="http://shifteleven.com/articles/tag/oop/feed" rel="self" type="application/rss+xml" />
	<link>http://shifteleven.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sat, 19 Sep 2009 11:19:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
		<item>
		<title>How to Create Objects in Object-Oriented JavaScript with Prototype</title>
		<link>http://shifteleven.com/articles/2007/04/29/how-to-create-objects-in-object-oriented-javascript-with-prototype</link>
		<comments>http://shifteleven.com/articles/2007/04/29/how-to-create-objects-in-object-oriented-javascript-with-prototype#comments</comments>
		<pubDate>Sun, 29 Apr 2007 10:40:22 +0000</pubDate>
		<dc:creator>K. Adam Christensen</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://dev.fecalrod.com/?p=28</guid>
		<description><![CDATA[Javascript Kata has a teriffic an article on how to create objects with JavaScript the old fashion way, without any JavaScript libraries.  But I use prototype and it has its very own way to create a classes.

Creating an empty class
In keeping with the cat theme of Javascript Kata, I will create my own Cat [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.javascriptkata.com">Javascript Kata</a> has a teriffic <a href="http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/">an article on how to create objects with JavaScript</a> the old fashion way, without any JavaScript libraries.  But I use <a href="http://www.prototypejs.org/">prototype</a> and it has its very own way to create a classes.</p>
<p><span id="more-28"></span></p>
<h3>Creating an empty class</h3>
<p>In keeping with the cat theme of Javascript Kata, I will create my own <code>Cat</code> class.  This is very easy to do; you simply create a new class and assign it to a variable.</p>
<pre class="javascript" title="code">  var Cat = Class.create();</pre>
<h3>Creating the constructor</h3>
<p>Unlike the Javascript Kata example, the constructor is not set inside of the function which created the class.  Instead it is put into the prototype attribute of the class, under the special method name <code>initialize</code>.</p>
<pre class="javascript" title="code">  var Cat = Class.create();
  Cat.prototype = {
    initialize: function(name) {
      this.name = name;
    }
  };</pre>
<h3>Adding a instance method</h3>
<p>To add an instance method to our <code>Cat</code> class, all one has to do is add another property to the prototype definition.</p>
<pre class="javascript" title="code">  var Cat = Class.create();
  Cat.prototype = {
    initialize: function(name) {
      this.name = name;
    },
    meow: function() {
      alert(this.name + " : meow!");
    }
  };</pre>
<p>What I like about this is it keeps all references to <code>this</code> in one spot.</p>
<h3>Making the cat meow</h3>
<p>The way that the code is constructed is different; however, the way to instantiate our Cat class is exactly the same as it would be if you didn&#8217;t use prototype.</p>
<pre class="javascript" title="code">  var mistigri = new Cat('Mistigri');
  mistigri.meow();</pre>
]]></content:encoded>
			<wfw:commentRss>http://shifteleven.com/articles/2007/04/29/how-to-create-objects-in-object-oriented-javascript-with-prototype/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
