<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.12-alpha" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Subclassing in JavaScript, part 1</title>
	<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1</link>
	<description>What happens at LShift</description>
	<pubDate>Sat, 06 Sep 2008 01:57:44 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.12-alpha</generator>

	<item>
		<title>by: M</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-95802</link>
		<pubDate>Mon, 12 May 2008 09:50:22 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-95802</guid>
					<description>&lt;p&gt;Hi,
I have tried an different techniques related to JavaScript inheritance subject.
The code and the explanation are to long to post them here so if anyone is interested to take a look over it you can find it at &lt;a&gt;www.dotnetcaffe.net&lt;/a&gt; under JavaScript category. Fell free to criticize the code in any way you want...just don't flame :).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I have tried an different techniques related to JavaScript inheritance subject.<br />
The code and the explanation are to long to post them here so if anyone is interested to take a look over it you can find it at <a>www.dotnetcaffe.net</a> under JavaScript category. Fell free to criticize the code in any way you want&#8230;just don&#8217;t flame :).</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Paul Crowley</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-65317</link>
		<pubDate>Wed, 05 Sep 2007 10:20:48 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-65317</guid>
					<description>&lt;p&gt;Bill T: I thought you had to use "traits objects" to get similar behaviour in Self, am I wrong?  Could you give a sample of Self code that illustrates the same behaviour in Self resulting from the use of clone()?  Thanks!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Bill T: I thought you had to use &#8220;traits objects&#8221; to get similar behaviour in Self, am I wrong?  Could you give a sample of Self code that illustrates the same behaviour in Self resulting from the use of clone()?  Thanks!</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bill T</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-65283</link>
		<pubDate>Wed, 05 Sep 2007 00:19:05 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-65283</guid>
					<description>&lt;p&gt;Actually, this is very much like Self's clone method. Maybe an example use would clarify:&lt;/p&gt;

&lt;blockquote&gt;
var parent = {a: 3};
var child = object(parent);
alert(child.a);                        // displays "3"
child.a = 4;
alert(child.a);                        // displays "4"
delete(child.a);
alert(child.a);                        // displays "3"
parent.a = 7;
alert(child.a);                        // displays "7"
&lt;/blockquote&gt;
</description>
		<content:encoded><![CDATA[<p>Actually, this is very much like Self&#8217;s clone method. Maybe an example use would clarify:</p>
<blockquote><p>
var parent = {a: 3};<br />
var child = object(parent);<br />
alert(child.a);                        // displays &#8220;3&#8243;<br />
child.a = 4;<br />
alert(child.a);                        // displays &#8220;4&#8243;<br />
delete(child.a);<br />
alert(child.a);                        // displays &#8220;3&#8243;<br />
parent.a = 7;<br />
alert(child.a);                        // displays &#8220;7&#8243;
</p></blockquote>
]]></content:encoded>
				</item>
	<item>
		<title>by: Paul Crowley</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-64978</link>
		<pubDate>Wed, 29 Aug 2007 07:36:33 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-64978</guid>
					<description>&lt;p&gt;Bill T: this is essentially the trick I discuss in Part 2. Although JavaScript calls this a "prototype" the name is misleading; it most closely resembles the vtable pointer of a class-based language.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Bill T: this is essentially the trick I discuss in Part 2. Although JavaScript calls this a &#8220;prototype&#8221; the name is misleading; it most closely resembles the vtable pointer of a class-based language.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bill T</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-64952</link>
		<pubDate>Tue, 28 Aug 2007 23:17:37 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-64952</guid>
					<description>&lt;p&gt;You write, "I don’t know how to make JavaScript behave like a sensible prototype-based language". Douglas Crockford writes:&lt;/p&gt;

&lt;blockquote&gt;function object(o) {
        function F() {}
        F.prototype = o;
        return new F();
}&lt;/blockquote&gt;

&lt;p&gt;Then, all you need to do is call &lt;code&gt;object(foo)&lt;/code&gt; to create an object whose prototype is &lt;code&gt;foo&lt;/code&gt;.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>You write, &#8220;I don’t know how to make JavaScript behave like a sensible prototype-based language&#8221;. Douglas Crockford writes:</p>
<blockquote><p>function object(o) {<br />
        function F() {}<br />
        F.prototype = o;<br />
        return new F();<br />
}</p></blockquote>
<p>Then, all you need to do is call <code>object(foo)</code> to create an object whose prototype is <code>foo</code>.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: fantomx11</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-51797</link>
		<pubDate>Fri, 27 Apr 2007 19:43:12 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-51797</guid>
					<description>&lt;p&gt;Here is my rewritten Child that doesn't have the problem you describe and doesn't require any helper functions to implement.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
function Child() {
    Parent.prototype.constructor.apply(this);
    this.somethingelse = "somethingelse";
}
&lt;/code&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here is my rewritten Child that doesn&#8217;t have the problem you describe and doesn&#8217;t require any helper functions to implement.</p>
<p><code><br />
function Child() {<br />
    Parent.prototype.constructor.apply(this);<br />
    this.somethingelse = "somethingelse";<br />
}<br />
</code></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: pdl_e</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-48864</link>
		<pubDate>Fri, 13 Apr 2007 12:39:46 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-48864</guid>
					<description>&lt;p&gt;There is another approach to implement JavaScript inheritance - a "lazy" inheritance which has all benefits of prototype-based inheritance like typed classes, but also eliminates necessity to declare external scripts in proper order and automatically resolves and loads (if necessary) dependencies to external scripts that contains related classes.
You can find more about it on &lt;a href="http://ajaxline.com/node/367" rel="nofollow"&gt;Alternate inheritance&lt;/a&gt;&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>There is another approach to implement JavaScript inheritance - a &#8220;lazy&#8221; inheritance which has all benefits of prototype-based inheritance like typed classes, but also eliminates necessity to declare external scripts in proper order and automatically resolves and loads (if necessary) dependencies to external scripts that contains related classes.<br />
You can find more about it on <a href="http://ajaxline.com/node/367" rel="nofollow">Alternate inheritance</a></p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jeff Watkins</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-9951</link>
		<pubDate>Tue, 12 Sep 2006 20:00:04 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-9951</guid>
					<description>&lt;p&gt;Sorry, your security code "feature" wiped out the long response, multiple examples, and explanations. I'll try to simply post a corrected version of your last example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
function Parent()
{
}
Parent.prototype.sharedArray= [];&lt;/p&gt;

&lt;p&gt;function Child()
{
    this.instanceMember= 5;
}
Child.prototype= new Parent;
Child.prototype.constructor= Child;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the &lt;em&gt;correct&lt;/em&gt; way to implement a shared property in JavaScript.&lt;/p&gt;

&lt;p&gt;The thing to keep in mind is that the object initialisers run for each new object created. Therefore, if you don't want a per-instance property, you need to define it on the prototype rather than in the initialiser.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Sorry, your security code &#8220;feature&#8221; wiped out the long response, multiple examples, and explanations. I&#8217;ll try to simply post a corrected version of your last example:</p>
<p><code><br />
function Parent()<br />
{<br />
}<br />
Parent.prototype.sharedArray= [];</code></p>
<p>function Child()<br />
{<br />
    this.instanceMember= 5;<br />
}<br />
Child.prototype= new Parent;<br />
Child.prototype.constructor= Child;
</p>
<p>This is the <em>correct</em> way to implement a shared property in JavaScript.</p>
<p>The thing to keep in mind is that the object initialisers run for each new object created. Therefore, if you don&#8217;t want a per-instance property, you need to define it on the prototype rather than in the initialiser.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: matthew</title>
		<link>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-5507</link>
		<pubDate>Mon, 24 Jul 2006 22:23:19 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/07/24/subclassing-in-javascript-part-1#comment-5507</guid>
					<description>&lt;p&gt;The last bit you describe about the children sharing the same parent instance reminds me of multiple virtual inheritance in C++. Except there you had to work to get such confusing behaviour - it seems so much easier in Javascript...!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>The last bit you describe about the children sharing the same parent instance reminds me of multiple virtual inheritance in C++. Except there you had to work to get such confusing behaviour - it seems so much easier in Javascript&#8230;!</p>
]]></content:encoded>
				</item>
</channel>
</rss>
