<?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: How to create objects in object-oriented javascript</title>
	<atom:link href="http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/</link>
	<description>Advanced katas for javascripters</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:10:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Alexwebmaster</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-719</link>
		<dc:creator>Alexwebmaster</dc:creator>
		<pubDate>Tue, 03 Mar 2009 10:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-719</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: How to make a singleton in javascript &#124; Javascript Kata</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-681</link>
		<dc:creator>How to make a singleton in javascript &#124; Javascript Kata</dc:creator>
		<pubDate>Tue, 02 Dec 2008 16:01:28 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-681</guid>
		<description>[...] writing a singleton, you need to know about creating objects and static [...]</description>
		<content:encoded><![CDATA[<p>[...] writing a singleton, you need to know about creating objects and static [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew Sazonov</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-26</link>
		<dc:creator>Andrew Sazonov</dc:creator>
		<pubDate>Tue, 01 May 2007 16:35:25 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-26</guid>
		<description>Yes, approach described in the post works. But unfortunately, it is far from being perfect...

Here is a link to an article which compares various techniques to implement inheritance in JavaScript (and their benefits and drawbacks):

http://www.soft-amis.org/jsiner/inheritance.html</description>
		<content:encoded><![CDATA[<p>Yes, approach described in the post works. But unfortunately, it is far from being perfect&#8230;</p>
<p>Here is a link to an article which compares various techniques to implement inheritance in JavaScript (and their benefits and drawbacks):</p>
<p><a href="http://www.soft-amis.org/jsiner/inheritance.html" rel="nofollow">http://www.soft-amis.org/jsiner/inheritance.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to Create Objects in Object-Oriented JavaScript with Prototype</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-25</link>
		<dc:creator>How to Create Objects in Object-Oriented JavaScript with Prototype</dc:creator>
		<pubDate>Sun, 29 Apr 2007 12:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-25</guid>
		<description>[...] 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 [...]</description>
		<content:encoded><![CDATA[<p>[...] 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 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-24</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 11 Apr 2007 20:43:06 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-24</guid>
		<description>Yeah! Jim&#039;s approach looks good but it can be hard to understand for beginners. I&#039;ll try to write about it in a near future...</description>
		<content:encoded><![CDATA[<p>Yeah! Jim&#8217;s approach looks good but it can be hard to understand for beginners. I&#8217;ll try to write about it in a near future&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Mercer</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-22</link>
		<dc:creator>David Mercer</dc:creator>
		<pubDate>Wed, 11 Apr 2007 15:46:43 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-22</guid>
		<description>I wrote:

&gt; My preferred approach is more along the lines of:

&gt; function Cat.prototype.meow(){â€¦}

As has been pointed out to me, Firefox chokes on this syntax.  I&#039;ve been using WSH to run Javascript, so never tried it in a browser.  It does work in IE, but not Firefox, so my approach is probably out for usage where you do not control script host.

Jim Plush wrote:

&quot;If you want to see pretty classes you could always do this:...&quot;

I like Jim&#039;s approach.</description>
		<content:encoded><![CDATA[<p>I wrote:</p>
<p>&gt; My preferred approach is more along the lines of:</p>
<p>&gt; function Cat.prototype.meow(){â€¦}</p>
<p>As has been pointed out to me, Firefox chokes on this syntax.  I&#8217;ve been using WSH to run Javascript, so never tried it in a browser.  It does work in IE, but not Firefox, so my approach is probably out for usage where you do not control script host.</p>
<p>Jim Plush wrote:</p>
<p>&#8220;If you want to see pretty classes you could always do this:&#8230;&#8221;</p>
<p>I like Jim&#8217;s approach.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jim Plush</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-23</link>
		<dc:creator>Jim Plush</dc:creator>
		<pubDate>Wed, 11 Apr 2007 15:31:43 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-23</guid>
		<description>I&#039;d have to agree with the author, using prototype over inner functions reduces the memory footprint. I have to work on 233mhz boxes and trust me, every little bit helps.

If you want to see pretty classes you could always do this:

function myClass() {}

myClass.prototype = {

       test:function() {

           alert(&#039;hi&#039;);
       },

       test2:function() {
           // something here
       }
};</description>
		<content:encoded><![CDATA[<p>I&#8217;d have to agree with the author, using prototype over inner functions reduces the memory footprint. I have to work on 233mhz boxes and trust me, every little bit helps.</p>
<p>If you want to see pretty classes you could always do this:</p>
<p>function myClass() {}</p>
<p>myClass.prototype = {</p>
<p>       test:function() {</p>
<p>           alert(&#8216;hi&#8217;);<br />
       },</p>
<p>       test2:function() {<br />
           // something here<br />
       }<br />
};</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Mercer</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-21</link>
		<dc:creator>David Mercer</dc:creator>
		<pubDate>Fri, 30 Mar 2007 21:33:50 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-21</guid>
		<description>William Murray wrote:

     &quot;I prefer to assign the methods within the main function...Any advantages or disadvantages to using this over prototype?&quot;

I used to prefer your method, too, but performance is significantly worse with your approach because every time you instantiate an object, a new function is created.

Mind you, most people treat Javascript as kind of a toy language and don&#039;t expect much performance from it, but detach the interpreter from the browser and you can write quite powerful programs with decent performance.

My preferred approach is more along the lines of:

function Cat.prototype.meow(){...}

rather than

Cat.prototype.meow = function(){...}

These work slightly different as functions (and, in this case, methods) declared like mine exist when the first line of the program executes.  Using the &quot;Cat.prototype.meow = function&quot; approach, the method will only exist after the program has executed that line of code.  Thus, my program could begin with the lines:

  var mistigri = new Cat(&#039;Mistigri&#039;);
  mistigri.meow();

Whereas the &quot;Cat.prototype.meow = function&quot; approach would choke on that, since the meow method does not exist yet.</description>
		<content:encoded><![CDATA[<p>William Murray wrote:</p>
<p>     &#8220;I prefer to assign the methods within the main function&#8230;Any advantages or disadvantages to using this over prototype?&#8221;</p>
<p>I used to prefer your method, too, but performance is significantly worse with your approach because every time you instantiate an object, a new function is created.</p>
<p>Mind you, most people treat Javascript as kind of a toy language and don&#8217;t expect much performance from it, but detach the interpreter from the browser and you can write quite powerful programs with decent performance.</p>
<p>My preferred approach is more along the lines of:</p>
<p>function Cat.prototype.meow(){&#8230;}</p>
<p>rather than</p>
<p>Cat.prototype.meow = function(){&#8230;}</p>
<p>These work slightly different as functions (and, in this case, methods) declared like mine exist when the first line of the program executes.  Using the &#8220;Cat.prototype.meow = function&#8221; approach, the method will only exist after the program has executed that line of code.  Thus, my program could begin with the lines:</p>
<p>  var mistigri = new Cat(&#8216;Mistigri&#8217;);<br />
  mistigri.meow();</p>
<p>Whereas the &#8220;Cat.prototype.meow = function&#8221; approach would choke on that, since the meow method does not exist yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ganeshji Marwaha</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-20</link>
		<dc:creator>Ganeshji Marwaha</dc:creator>
		<pubDate>Tue, 27 Mar 2007 19:34:40 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-20</guid>
		<description>Dan - What i meant was, in other OO languages, take java for example, you have an enclosed view of a class and its methods.

Class Test {
   public void tryMe() {
     System.out.println(&quot;tried&quot;);
   }
}

Where as, using the prototype technique, you don&#039;t get such an enclosed view. I don&#039;t tend to see this as a disadvantage, rather as something that will be visually more appealing.</description>
		<content:encoded><![CDATA[<p>Dan &#8211; What i meant was, in other OO languages, take java for example, you have an enclosed view of a class and its methods.</p>
<p>Class Test {<br />
   public void tryMe() {<br />
     System.out.println(&#8220;tried&#8221;);<br />
   }<br />
}</p>
<p>Where as, using the prototype technique, you don&#8217;t get such an enclosed view. I don&#8217;t tend to see this as a disadvantage, rather as something that will be visually more appealing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.javascriptkata.com/2007/03/23/how-to-create-objects-in-object-oriented-javascript/comment-page-1/#comment-16</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Sun, 25 Mar 2007 21:06:33 +0000</pubDate>
		<guid isPermaLink="false">http://javascriptkata.timmyontime.com/?p=11#comment-16</guid>
		<description>William, pardon me for my late response but Akismet marked your comment as spam. I will have to be more careful and have an eye over it...

The disadvantage of doing it that way is that it uses more memory. You can see in another of my post about advatages of using prototypes : &quot;It uses less memory because javascript creates only one instance of the function and uses references to it.&quot; (http://www.javascriptkata.com/2007/03/21/what-are-javascript-prototypes-short-answer-for-advanced-javascripters/).

Thanks for the comment!</description>
		<content:encoded><![CDATA[<p>William, pardon me for my late response but Akismet marked your comment as spam. I will have to be more careful and have an eye over it&#8230;</p>
<p>The disadvantage of doing it that way is that it uses more memory. You can see in another of my post about advatages of using prototypes : &#8220;It uses less memory because javascript creates only one instance of the function and uses references to it.&#8221; (<a href="http://www.javascriptkata.com/2007/03/21/what-are-javascript-prototypes-short-answer-for-advanced-javascripters/" rel="nofollow">http://www.javascriptkata.com/2007/03/21/what-are-javascript-prototypes-short-answer-for-advanced-javascripters/</a>).</p>
<p>Thanks for the comment!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
