<?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 2</title>
	<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2</link>
	<description>What happens at LShift</description>
	<pubDate>Wed, 07 Jan 2009 02:21:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.12-alpha</generator>

	<item>
		<title>by: Paul Crowley</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-47944</link>
		<pubDate>Tue, 10 Apr 2007 12:22:42 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-47944</guid>
					<description>&lt;p&gt;Laziness seems orthogonal to the problem addressed here, no?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Laziness seems orthogonal to the problem addressed here, no?</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Andrew Sazonov</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-47939</link>
		<pubDate>Tue, 10 Apr 2007 10:27:43 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-47939</guid>
					<description>&lt;p&gt;There is another approach to implement JavaScript inheritance - a “lazy” inheritance which has all benefits of “prototype” based approach 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.
This approach is supported by JSINER library - you can find more about it on http://www.soft-amis.com/jsiner/inheritance.html&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>There is another approach to implement JavaScript inheritance - a “lazy” inheritance which has all benefits of “prototype” based approach 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 />
This approach is supported by JSINER library - you can find more about it on http://www.soft-amis.com/jsiner/inheritance.html</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Dan</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-43124</link>
		<pubDate>Thu, 15 Mar 2007 19:51:40 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-43124</guid>
					<description>&lt;p&gt;Thanks Paul &#38; Jeff for sharing your solutions - had the same original problem, and I eventually used the .call() method and it worked fine. Thanks!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Thanks Paul &amp; Jeff for sharing your solutions - had the same original problem, and I eventually used the .call() method and it worked fine. Thanks!</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: ravi</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-17835</link>
		<pubDate>Wed, 22 Nov 2006 09:45:05 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-17835</guid>
					<description>&lt;p&gt;no ckomment&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>no ckomment</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Paul Crowley</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-9974</link>
		<pubDate>Wed, 13 Sep 2006 09:52:18 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-9974</guid>
					<description>&lt;p&gt;I've just added&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;print(aa instanceof Child);
print(aa instanceof Parent);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to the end of that code, and it prints&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;true
true
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;"A instanceof F" tests if F.prototype appears in the prototype chain for A, which it does in this instance.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I&#8217;ve just added</p>
<pre><code>print(aa instanceof Child);
print(aa instanceof Parent);
</code></pre>
<p>to the end of that code, and it prints</p>
<pre><code>true
true
</code></pre>
<p>&#8220;A instanceof F&#8221; tests if F.prototype appears in the prototype chain for A, which it does in this instance.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jeff Watkins</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-9958</link>
		<pubDate>Tue, 12 Sep 2006 20:10:43 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-9958</guid>
					<description>&lt;p&gt;Damn, formatting is screwed up again.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Damn, formatting is screwed up again.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Jeff Watkins</title>
		<link>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-9957</link>
		<pubDate>Tue, 12 Sep 2006 20:10:12 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/08/03/subclassing-in-javascript-part-2#comment-9957</guid>
					<description>&lt;p&gt;Paul, it looks like you've broken the prototype chain with your extend function. Because the initialiser you return from extend doesn't directly refer to the "parent" initialiser you won't be able to use code similar to the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
var c= new Child();
if (c instanceof Parent)
   //  clever processing here
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you're looking for a general purpose helper for inheritence you might consider something like the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
Function.prototype.extendsClass= function( base )
{
    this.prototype= new base();
    this.prototype.constructor= this;
}
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you can write your initialisers like the following:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;
function Parent( name )
{
    this.name= name;
}
Parent.prototype.sharedArray= [];
&lt;/code&gt;
&lt;code&gt;
function Child( first, last )
{
    Parent.call( this, first + " " + last );
}
Child.extendsClass( Parent );
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then you can fully use the instanceof operator.&lt;/p&gt;

&lt;p&gt;Just a thought...&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Paul, it looks like you&#8217;ve broken the prototype chain with your extend function. Because the initialiser you return from extend doesn&#8217;t directly refer to the &#8220;parent&#8221; initialiser you won&#8217;t be able to use code similar to the following:</p>
<p><code><br />
var c= new Child();<br />
if (c instanceof Parent)<br />
   //  clever processing here<br />
</code></p>
<p>If you&#8217;re looking for a general purpose helper for inheritence you might consider something like the following:</p>
<p><code><br />
Function.prototype.extendsClass= function( base )<br />
{<br />
    this.prototype= new base();<br />
    this.prototype.constructor= this;<br />
}<br />
</code></p>
<p>Then you can write your initialisers like the following:</p>
<p><code><br />
function Parent( name )<br />
{<br />
    this.name= name;<br />
}<br />
Parent.prototype.sharedArray= [];<br />
</code><br />
<code><br />
function Child( first, last )<br />
{<br />
    Parent.call( this, first + " " + last );<br />
}<br />
Child.extendsClass( Parent );<br />
</code></p>
<p>Then you can fully use the instanceof operator.</p>
<p>Just a thought&#8230;</p>
]]></content:encoded>
				</item>
</channel>
</rss>
