<?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: JavaScript inheritance &#8211; how and why</title>
	<atom:link href="http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/feed/" rel="self" type="application/rss+xml" />
	<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/</link>
	<description>Web development and Internet trends</description>
	<lastBuildDate>Sat, 20 Mar 2010 05:17:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Robert Nyman</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-613463</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Tue, 08 Dec 2009 19:46:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-613463</guid>
		<description>Juan,

Thanks for the link!

Michael,

Thanks for sharing! There are some interesting things in there, although my preferred approach is the native prototype syntax for readability, code handover and for being there native in the language without dependencies.</description>
		<content:encoded><![CDATA[<p>Juan,</p>
<p>Thanks for the link!</p>
<p>Michael,</p>
<p>Thanks for sharing! There are some interesting things in there, although my preferred approach is the native prototype syntax for readability, code handover and for being there native in the language without dependencies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael .H</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-613457</link>
		<dc:creator>Michael .H</dc:creator>
		<pubDate>Tue, 08 Dec 2009 18:09:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-613457</guid>
		<description>I observed one thing about Base2 and Prototype. When you call a chain method and you reach the base method, inside the method you have access to the derived object members using “this”. In my opinion once the call is navigating thru the chain on each base class the user should not be able to access the derived class members based on OOP definitions. I also tried a different approach of JavaScript inheritance, it can make use of closures or prototype, it’s up to the way you want to implement it &lt;a href=&quot;”&quot; rel=&quot;nofollow&quot;&gt; http://dotnetcaffe.blogspot.com/2009/12/javascript-inheritance.html&lt;/a&gt;. Regarding what Juan Mendes mentioned about surrogate constructors. Even if it’s more light weight as memory consumption I don’t find elegant. In my case if the base class constructor requires parameters they will be passed from the derived class. Here is an example:

var Human = MG.Class.Create({
                Gender: null,
                constructor: function(gender) {
                    this.Gender = gender;
                },

                GenderString: function() {
                    return this.Gender == &#039;F&#039; ? &quot;female&quot; : &quot;male&quot;;
                },

                ToOverride: function() { return &quot;Called from Human&quot;; }
            }, null, null);
            
            var Individual = MG.Class.Create({
                Unique: null,
                constructor: function(unique) {
                    this.Unique = unique;
                },

                IsUnique: function() {
                    return this.Unique ? &quot;Yes&quot; : &quot;No&quot;;
                },

                ToOverride: function() { return &quot;Called from Individual which is &quot; + (this.Unique ? &quot;unique&quot; : &quot;not unique&quot;) + &quot; / &quot; + this.base(); }
            }, Human, null);

			var objHuman = new Human(&quot;F&quot;);
            var objIndividual = new Individual(true, &quot;M&quot;);

In my opinion also a check for parameters of the base constructor should be added. If the derived object does not provide on instantiation the correct number or parameters for the base, then an exception should be triggered.</description>
		<content:encoded><![CDATA[<p>I observed one thing about Base2 and Prototype. When you call a chain method and you reach the base method, inside the method you have access to the derived object members using “this”. In my opinion once the call is navigating thru the chain on each base class the user should not be able to access the derived class members based on OOP definitions. I also tried a different approach of JavaScript inheritance, it can make use of closures or prototype, it’s up to the way you want to implement it <a href="”" rel="nofollow"> </a><a href="http://dotnetcaffe.blogspot.com/2009/12/javascript-inheritance.html" rel="nofollow">http://dotnetcaffe.blogspot.com/2009/12/javascript-inheritance.html</a>. Regarding what Juan Mendes mentioned about surrogate constructors. Even if it’s more light weight as memory consumption I don’t find elegant. In my case if the base class constructor requires parameters they will be passed from the derived class. Here is an example:</p>
<p>var Human = MG.Class.Create({<br />
                Gender: null,<br />
                constructor: function(gender) {<br />
                    this.Gender = gender;<br />
                },</p>
<p>                GenderString: function() {<br />
                    return this.Gender == &#8216;F&#8217; ? &#8220;female&#8221; : &#8220;male&#8221;;<br />
                },</p>
<p>                ToOverride: function() { return &#8220;Called from Human&#8221;; }<br />
            }, null, null);</p>
<p>            var Individual = MG.Class.Create({<br />
                Unique: null,<br />
                constructor: function(unique) {<br />
                    this.Unique = unique;<br />
                },</p>
<p>                IsUnique: function() {<br />
                    return this.Unique ? &#8220;Yes&#8221; : &#8220;No&#8221;;<br />
                },</p>
<p>                ToOverride: function() { return &#8220;Called from Individual which is &#8221; + (this.Unique ? &#8220;unique&#8221; : &#8220;not unique&#8221;) + &#8221; / &#8221; + this.base(); }<br />
            }, Human, null);</p>
<p>			var objHuman = new Human(&#8220;F&#8221;);<br />
            var objIndividual = new Individual(true, &#8220;M&#8221;);</p>
<p>In my opinion also a check for parameters of the base constructor should be added. If the derived object does not provide on instantiation the correct number or parameters for the base, then an exception should be triggered.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan Mendes</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-609891</link>
		<dc:creator>Juan Mendes</dc:creator>
		<pubDate>Thu, 12 Nov 2009 16:04:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-609891</guid>
		<description>Here&#039;s a link to an interesting article at extjs that mentions some pitfalls of  getting too &quot;inheritance happy&quot;. See the part under &quot;Create a subclass (Option 2)&quot;

http://www.extjs.com/blog/2009/11/11/advanced-plugin-development-with-ext-js/

Not sure how much you care about extjs, but the one of his points is that added functionality through subclassing prohibits the reuse of that functionality in other classes:</description>
		<content:encoded><![CDATA[<p>Here&#8217;s a link to an interesting article at extjs that mentions some pitfalls of  getting too &#8220;inheritance happy&#8221;. See the part under &#8220;Create a subclass (Option 2)&#8221;</p>
<p><a href="http://www.extjs.com/blog/2009/11/11/advanced-plugin-development-with-ext-js/" rel="nofollow">http://www.extjs.com/blog/2009/11/11/advanced-plugin-development-with-ext-js/</a></p>
<p>Not sure how much you care about extjs, but the one of his points is that added functionality through subclassing prohibits the reuse of that functionality in other classes:</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-609759</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Wed, 11 Nov 2009 09:20:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-609759</guid>
		<description>Juan Mendes,

I&#039;d like to correct/clarify my statement in the article: I definitely believe there is need and use for inheritance, what I was going for is that probably isn&#039;t need to be in the fashion it is with class-based models (i.e. &quot;super&quot;-calling etc).

Thanks for the code, it was interesting!

At the end of the day, though, I think we all need to consider what we need and what till be our best way to do it: there&#039;s no golden solution for any situation.</description>
		<content:encoded><![CDATA[<p>Juan Mendes,</p>
<p>I&#8217;d like to correct/clarify my statement in the article: I definitely believe there is need and use for inheritance, what I was going for is that probably isn&#8217;t need to be in the fashion it is with class-based models (i.e. &#8220;super&#8221;-calling etc).</p>
<p>Thanks for the code, it was interesting!</p>
<p>At the end of the day, though, I think we all need to consider what we need and what till be our best way to do it: there&#8217;s no golden solution for any situation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juan Mendes</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-609691</link>
		<dc:creator>Juan Mendes</dc:creator>
		<pubDate>Tue, 10 Nov 2009 20:30:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-609691</guid>
		<description>I have a number of comments. Embracing Javascript is one thing. Saying that there&#039;s no use for inheritance on the client-side of web apps is just too far fetched. It is true that people misuse inheritance, but that doesn&#039;t mean there&#039;s on use for it. Douglas may not have found uses for it, maybe because he hasn&#039;t built a system where components are built on top of other components. In the DOM, everything extends Element. In Ext-js everything is a component and that allows for code to treat any subclasses simply as a component.

Enough of that, let&#039;s talk about your approach to using inheritance. This approach suffers from a problem. What if your base class requires parameters to be initialized?  Even worse, what if there are side effects to the base class being instantiated? You can&#039;t just call the constructor to establish inheritance. You could if you hacked all your constructors to know that they were being called for inheritance. That would just be plain ugly

However, there is a solution to this which involves surrogate constructors. This was developed by a co-worker here at our company within a library he wrote called class.js. Basically this is what you would do.
&lt;code&gt;
// Function to be used as a surrogate constructor to avoid 
// instantiating a parent class just to setup inheritance
function surrogateCtor() {}

function Being (name) {
  this.name = name;
  console.log(&#039;Being constructor called&#039;);
}

Being.prototype.breathes = function () {
  return true;
};

// An object which inherits Being:
function Human(name, blogs) {
  this.blogs = blogs;
  // Call the super constructor
  Being.call(this, name);
}

// Establish inheritance without calling the parent&#039;s constructor
surrogateCtor.prototype = Being.prototype;
Human.prototype = new surrogateCtor();
// Set the constructor back on the prototype since we used some trickery
Human.prototype.constructor = Human;

Human.prototype.getsBored = function () {
  return !this.blogs;
}; 

// ------ Testing code------------------
var rob = new Human(&quot;Robert&quot;, true);

console.log(&quot;Name is &quot; + rob.name);
console.log(&quot;Breathes:&quot; + rob.breathes())
console.log(&quot;Gets bored:&quot; + rob.getsBored())

// Outputs:
// Being constructor called (just once, awesome)
// Name is Robert
// Breathes:true
// Gets bored: false
&lt;/code&gt;

This could be abstracted with the following code
&lt;code&gt;
Function.prototype.extend = (function() {
  function surrogateCtor (){};
  
  return function(parentCtor) {
    surrogateCtor.prototype = parentCtor.prototype;
    this.prototype = new surrogateCtor();
    this.prototype.constructor = this;
  };
})();

// Abstract base class
function Shape() {}
// Extending classes must override these two methods
Shape.prototype.getSideCount = function (){};
Shape.prototype.getSideLength = function (){};
// Common functionality in base
Shape.prototype.getPerimeter = function () {
  return this.getSideCount() * this.getSideLength();
}

// Extends Shape
function Triangle(sideLength) {
  this.sideLength = sideLength;
}
// Extend must be called before adding props to the prototype
Triangle.extend(Shape);

Triangle.prototype.getSideCount = function() {
  return 3;
}

Triangle.prototype.getSideLength = function() {
  return this.sideLength;
}


// --- Testing code -----
var tri = new Triangle(5);
console.log(tri.getPerimeter());// outputs 15
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I have a number of comments. Embracing Javascript is one thing. Saying that there&#8217;s no use for inheritance on the client-side of web apps is just too far fetched. It is true that people misuse inheritance, but that doesn&#8217;t mean there&#8217;s on use for it. Douglas may not have found uses for it, maybe because he hasn&#8217;t built a system where components are built on top of other components. In the DOM, everything extends Element. In Ext-js everything is a component and that allows for code to treat any subclasses simply as a component.</p>
<p>Enough of that, let&#8217;s talk about your approach to using inheritance. This approach suffers from a problem. What if your base class requires parameters to be initialized?  Even worse, what if there are side effects to the base class being instantiated? You can&#8217;t just call the constructor to establish inheritance. You could if you hacked all your constructors to know that they were being called for inheritance. That would just be plain ugly</p>
<p>However, there is a solution to this which involves surrogate constructors. This was developed by a co-worker here at our company within a library he wrote called class.js. Basically this is what you would do.<br />
<code><br />
// Function to be used as a surrogate constructor to avoid<br />
// instantiating a parent class just to setup inheritance<br />
function surrogateCtor() {}</p>
<p>function Being (name) {<br />
  this.name = name;<br />
  console.log('Being constructor called');<br />
}</p>
<p>Being.prototype.breathes = function () {<br />
  return true;<br />
};</p>
<p>// An object which inherits Being:<br />
function Human(name, blogs) {<br />
  this.blogs = blogs;<br />
  // Call the super constructor<br />
  Being.call(this, name);<br />
}</p>
<p>// Establish inheritance without calling the parent's constructor<br />
surrogateCtor.prototype = Being.prototype;<br />
Human.prototype = new surrogateCtor();<br />
// Set the constructor back on the prototype since we used some trickery<br />
Human.prototype.constructor = Human;</p>
<p>Human.prototype.getsBored = function () {<br />
  return !this.blogs;<br />
}; </p>
<p>// ------ Testing code------------------<br />
var rob = new Human("Robert", true);</p>
<p>console.log("Name is " + rob.name);<br />
console.log("Breathes:" + rob.breathes())<br />
console.log("Gets bored:" + rob.getsBored())</p>
<p>// Outputs:<br />
// Being constructor called (just once, awesome)<br />
// Name is Robert<br />
// Breathes:true<br />
// Gets bored: false<br />
</code></p>
<p>This could be abstracted with the following code<br />
<code><br />
Function.prototype.extend = (function() {<br />
  function surrogateCtor (){};</p>
<p>  return function(parentCtor) {<br />
    surrogateCtor.prototype = parentCtor.prototype;<br />
    this.prototype = new surrogateCtor();<br />
    this.prototype.constructor = this;<br />
  };<br />
})();</p>
<p>// Abstract base class<br />
function Shape() {}<br />
// Extending classes must override these two methods<br />
Shape.prototype.getSideCount = function (){};<br />
Shape.prototype.getSideLength = function (){};<br />
// Common functionality in base<br />
Shape.prototype.getPerimeter = function () {<br />
  return this.getSideCount() * this.getSideLength();<br />
}</p>
<p>// Extends Shape<br />
function Triangle(sideLength) {<br />
  this.sideLength = sideLength;<br />
}<br />
// Extend must be called before adding props to the prototype<br />
Triangle.extend(Shape);</p>
<p>Triangle.prototype.getSideCount = function() {<br />
  return 3;<br />
}</p>
<p>Triangle.prototype.getSideLength = function() {<br />
  return this.sideLength;<br />
}</p>
<p>// --- Testing code -----<br />
var tri = new Triangle(5);<br />
console.log(tri.getPerimeter());// outputs 15<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rajakvk</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-601359</link>
		<dc:creator>rajakvk</dc:creator>
		<pubDate>Tue, 15 Sep 2009 17:41:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-601359</guid>
		<description>&lt;blockquote cite=&quot;&quot;&gt;I would humbly like to ask of you to embrace JavaScript. &lt;/cite&gt;

Well said...</description>
		<content:encoded><![CDATA[<blockquote cite=""><p>I would humbly like to ask of you to embrace JavaScript. </p>
<p>Well said&#8230;</p></blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: JavaScript namespacing - an alternative to JavaScript inheritance - Robert&#8217;s talk - Web development and Internet trends</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-468007</link>
		<dc:creator>JavaScript namespacing - an alternative to JavaScript inheritance - Robert&#8217;s talk - Web development and Internet trends</dc:creator>
		<pubDate>Wed, 29 Oct 2008 16:10:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-468007</guid>
		<description>[...] talking about JavaScript and inheritance, something that often go amiss from the discussion is the alternative of using proper namespacing [...]</description>
		<content:encoded><![CDATA[<p>[...] talking about JavaScript and inheritance, something that often go amiss from the discussion is the alternative of using proper namespacing [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-466875</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Wed, 22 Oct 2008 18:43:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-466875</guid>
		<description>Anders,


:-)</description>
		<content:encoded><![CDATA[<p>Anders,</p>
<p> <img src='http://robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders YtterstrÃ¶m</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-466862</link>
		<dc:creator>Anders YtterstrÃ¶m</dc:creator>
		<pubDate>Wed, 22 Oct 2008 17:13:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-466862</guid>
		<description>Robert,

The three of us whom write javascript has a silent agreement to avoid it, I think. There are times when it is tempting to do it just because you can, but one use to find a more straightforward way to solve the problem during the coffee break. :)</description>
		<content:encoded><![CDATA[<p>Robert,</p>
<p>The three of us whom write javascript has a silent agreement to avoid it, I think. There are times when it is tempting to do it just because you can, but one use to find a more straightforward way to solve the problem during the coffee break. <img src='http://robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JavaScript inheritance - experimenting with syntax alternatives and private variables - Robert&#8217;s talk - Web development and Internet trends</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-466695</link>
		<dc:creator>JavaScript inheritance - experimenting with syntax alternatives and private variables - Robert&#8217;s talk - Web development and Internet trends</dc:creator>
		<pubDate>Tue, 21 Oct 2008 21:33:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-466695</guid>
		<description>[...] reading this article, I strongly recommend reading JavaScript inheritance - how and why and Explaining JavaScript scope and closures first, since many phenomenon below will have their [...]</description>
		<content:encoded><![CDATA[<p>[...] reading this article, I strongly recommend reading JavaScript inheritance &#8211; how and why and Explaining JavaScript scope and closures first, since many phenomenon below will have their [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JavaScript: how to get private, privileged, public and static members (properties and methods) - Robert&#8217;s talk - Web development and Internet trends</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-461714</link>
		<dc:creator>JavaScript: how to get private, privileged, public and static members (properties and methods) - Robert&#8217;s talk - Web development and Internet trends</dc:creator>
		<pubDate>Tue, 14 Oct 2008 11:26:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-461714</guid>
		<description>[...] reading JavaScript inheritance - how and why and Explaining JavaScript scope and closures, I thought we&#8217;d combine the knowledge gained to [...]</description>
		<content:encoded><![CDATA[<p>[...] reading JavaScript inheritance &#8211; how and why and Explaining JavaScript scope and closures, I thought we&#8217;d combine the knowledge gained to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-454721</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Wed, 08 Oct 2008 06:46:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-454721</guid>
		<description>Stefan,

Thanks for sharing! I was hoping someone would express their love for a class-based approach. :-)

It depends on a few factors, as you say: in very, very large projects it might become useful, but my estimate is, like you say, that memory usage will increase (and while not dramatically, every byte counts for me).

In terms of private and protected properties and methods, the Yahoo Module Pattern offers you just that: one part which can be private and another with protected or public methods.

Regarding your JavaScript framework, if it ever becomes official, please let me know! :-)</description>
		<content:encoded><![CDATA[<p>Stefan,</p>
<p>Thanks for sharing! I was hoping someone would express their love for a class-based approach. <img src='http://robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>It depends on a few factors, as you say: in very, very large projects it might become useful, but my estimate is, like you say, that memory usage will increase (and while not dramatically, every byte counts for me).</p>
<p>In terms of private and protected properties and methods, the Yahoo Module Pattern offers you just that: one part which can be private and another with protected or public methods.</p>
<p>Regarding your JavaScript framework, if it ever becomes official, please let me know! <img src='http://robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stefan Van Reeth</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-454243</link>
		<dc:creator>Stefan Van Reeth</dc:creator>
		<pubDate>Tue, 07 Oct 2008 21:05:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-454243</guid>
		<description>You hava a strong case Robert, and I agree that for websites your approach is certainly the way to go. JavaScript is prototype based and should be used as such.

However, I feel that in some cases it can be real usefull to mimic class based languages in some respects. Again it&#039;s utterly dependent on user case and personal style, but for larger codebases, I prefer such an approach. However, this has issues as u describe.

What is needed for the class based emulation approach is something that gives us the goodies from other languages, without sacrificing native js syntax and behaviour. I do know a solution, but it&#039;s in-house developed (I own it, but I agreed not to make it public yet). Forgive me to bring it up here, but I need it to illustrate my views.

To cut short, it&#039;s possible to merge the two approaches gracefully. At home I can make class-like structures that I can use the native way, without any further calls to Class.extend() or something similiar. All magic is done by putting a few calls into the constructor and after that u can instantiate the classical way (ie with &#039;new&#039;).

Since I constructed this little lib, my productivity has increased dramatically. I now can have private, protected and static methods/properties. I have access control to classes and methods. When debugging I now get meaningfull errors, my objects can be introspected without writing endless for-in loops, etc. The trade-off is an increased memory usage, but that only shows when one creates something silly like 100.000 classes, and even then we&#039;re not talking megabytes here.

While I agree that such things are overkill for ordinary websites, for larger projects I feel classical js falls short. At some point it pays off to start using a framework, if only to make the codebase easier to maintain. The way I use MF - Mystery Framework ;) - I have the best of both worlds. I have all the benefits of js prototypical nature AND the ease of constraints like we know from Java. Lovely when the codebase surpasses the 1000 lines or so.

Forgive me this elaborate post again, but it has been a while and I don&#039;t seem to be able to post anything short anyway :D

Cheers to all that made it this far!!!</description>
		<content:encoded><![CDATA[<p>You hava a strong case Robert, and I agree that for websites your approach is certainly the way to go. JavaScript is prototype based and should be used as such.</p>
<p>However, I feel that in some cases it can be real usefull to mimic class based languages in some respects. Again it&#8217;s utterly dependent on user case and personal style, but for larger codebases, I prefer such an approach. However, this has issues as u describe.</p>
<p>What is needed for the class based emulation approach is something that gives us the goodies from other languages, without sacrificing native js syntax and behaviour. I do know a solution, but it&#8217;s in-house developed (I own it, but I agreed not to make it public yet). Forgive me to bring it up here, but I need it to illustrate my views.</p>
<p>To cut short, it&#8217;s possible to merge the two approaches gracefully. At home I can make class-like structures that I can use the native way, without any further calls to Class.extend() or something similiar. All magic is done by putting a few calls into the constructor and after that u can instantiate the classical way (ie with &#8216;new&#8217;).</p>
<p>Since I constructed this little lib, my productivity has increased dramatically. I now can have private, protected and static methods/properties. I have access control to classes and methods. When debugging I now get meaningfull errors, my objects can be introspected without writing endless for-in loops, etc. The trade-off is an increased memory usage, but that only shows when one creates something silly like 100.000 classes, and even then we&#8217;re not talking megabytes here.</p>
<p>While I agree that such things are overkill for ordinary websites, for larger projects I feel classical js falls short. At some point it pays off to start using a framework, if only to make the codebase easier to maintain. The way I use MF &#8211; Mystery Framework <img src='http://robertnyman.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  &#8211; I have the best of both worlds. I have all the benefits of js prototypical nature AND the ease of constraints like we know from Java. Lovely when the codebase surpasses the 1000 lines or so.</p>
<p>Forgive me this elaborate post again, but it has been a while and I don&#8217;t seem to be able to post anything short anyway <img src='http://robertnyman.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Cheers to all that made it this far!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-454104</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Tue, 07 Oct 2008 18:02:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-454104</guid>
		<description>mdmadph,

But is that the framework pushing you into using it, or just that it would&#039;ve been needed when you had it, no matter which JavaScript library you were using?</description>
		<content:encoded><![CDATA[<p>mdmadph,</p>
<p>But is that the framework pushing you into using it, or just that it would&#8217;ve been needed when you had it, no matter which JavaScript library you were using?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mdmadph</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-452950</link>
		<dc:creator>mdmadph</dc:creator>
		<pubDate>Mon, 06 Oct 2008 20:49:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-452950</guid>
		<description>In ExtJS, I&#039;ve actually used super functions here and there, cause there&#039;s so much inheritance going on everywhere, but that&#039;s about it.</description>
		<content:encoded><![CDATA[<p>In ExtJS, I&#8217;ve actually used super functions here and there, cause there&#8217;s so much inheritance going on everywhere, but that&#8217;s about it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Robert Nyman</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-452865</link>
		<dc:creator>Robert Nyman</dc:creator>
		<pubDate>Mon, 06 Oct 2008 19:24:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-452865</guid>
		<description>Steven,

Interesting, thanks for the tip!

Anders,

Glad you liked it! The metaprogramming chapter is my favorite chapter in a JavaScript ever (or at least for a long long time)!

Kudos for using &lt;a href=&quot;http://www.robertnyman.com/dlite/&quot; rel=&quot;nofollow&quot;&gt;dLite&lt;/a&gt;!

By the way, would you say that by using Prototype at work for inheritance, that you might overuse inheritance inadvertedly or not?

Andrea,

Thanks! I haven&#039;t fully read your document, but it looks quite good!</description>
		<content:encoded><![CDATA[<p>Steven,</p>
<p>Interesting, thanks for the tip!</p>
<p>Anders,</p>
<p>Glad you liked it! The metaprogramming chapter is my favorite chapter in a JavaScript ever (or at least for a long long time)!</p>
<p>Kudos for using <a href="http://www.robertnyman.com/dlite/" rel="nofollow">dLite</a>!</p>
<p>By the way, would you say that by using Prototype at work for inheritance, that you might overuse inheritance inadvertedly or not?</p>
<p>Andrea,</p>
<p>Thanks! I haven&#8217;t fully read your document, but it looks quite good!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrea Giammarchi</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-452246</link>
		<dc:creator>Andrea Giammarchi</dc:creator>
		<pubDate>Mon, 06 Oct 2008 08:42:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-452246</guid>
		<description>Hi Robert, good stuff as usual :-)

The only thing is: why people completely ignore &lt;a href=&quot;http://www.3site.eu/doc/&quot; rel=&quot;nofollow&quot;&gt;my document&lt;/a&gt;? :P</description>
		<content:encoded><![CDATA[<p>Hi Robert, good stuff as usual <img src='http://robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>The only thing is: why people completely ignore <a href="http://www.3site.eu/doc/" rel="nofollow">my document</a>? <img src='http://robertnyman.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anders YtterstrÃ¶m</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-452239</link>
		<dc:creator>Anders YtterstrÃ¶m</dc:creator>
		<pubDate>Mon, 06 Oct 2008 08:33:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-452239</guid>
		<description>Nice read! Yesterday I finished reading about metaprogramming in JavaScript (Art and Science of JavaScript, Sitepoint), so it was a good coincidence that you blogged about it.

Since I&#039;m bound to Prototype in my current project at work, I stick to their class-like inheritence during office-time. On my own though (no libraries here except DLite), I will start to use the module pattern since it make sense to me.</description>
		<content:encoded><![CDATA[<p>Nice read! Yesterday I finished reading about metaprogramming in JavaScript (Art and Science of JavaScript, Sitepoint), so it was a good coincidence that you blogged about it.</p>
<p>Since I&#8217;m bound to Prototype in my current project at work, I stick to their class-like inheritence during office-time. On my own though (no libraries here except DLite), I will start to use the module pattern since it make sense to me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Clark</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-451825</link>
		<dc:creator>Steven Clark</dc:creator>
		<pubDate>Sun, 05 Oct 2008 23:41:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-451825</guid>
		<description>Its at about 35 minutes into episode 2. Sorry I should have mentioned that. :)</description>
		<content:encoded><![CDATA[<p>Its at about 35 minutes into episode 2. Sorry I should have mentioned that. <img src='http://robertnyman.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven Clark</title>
		<link>http://robertnyman.com/2008/10/06/javascript-inheritance-how-and-why/#comment-451824</link>
		<dc:creator>Steven Clark</dc:creator>
		<pubDate>Sun, 05 Oct 2008 23:40:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.robertnyman.com/?p=865#comment-451824</guid>
		<description>Interesting, I&#039;ve done a fair bit of Java and understand class inheritance well enough, but JavaScript I&#039;m pretty weak on...

If you&#039;ve missed it (which I&#039;d be surprised) the Open Web Podcast episode 2 has a bit of a discussion of the inheritance issue, which is kind of interesting.

http://openwebpodcast.com/</description>
		<content:encoded><![CDATA[<p>Interesting, I&#8217;ve done a fair bit of Java and understand class inheritance well enough, but JavaScript I&#8217;m pretty weak on&#8230;</p>
<p>If you&#8217;ve missed it (which I&#8217;d be surprised) the Open Web Podcast episode 2 has a bit of a discussion of the inheritance issue, which is kind of interesting.</p>
<p><a href="http://openwebpodcast.com/" rel="nofollow">http://openwebpodcast.com/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
