There are several approaches to forcing JavaScript inheritance to behave like other, more natively-OOP languages, from Dean Edwards Base.js, to John Resig’s take on it, to the approaches used by Prototype.js and MooTools (my personal recommendation). This is something jQuery doesn’t even attempt (although some less impressive plugins are available), which is one reason I don’t understand how anyone can rationally compare jQuery to MooTools.

Some of the approaches above (including Dean Edwards’ approach, and the framework/toolkits) also address other issues, such as initializing non-primitive members for each instance (which is very handy), or binding scope (ala MooTools Binds implementation). As always, I’m a big fan of the upshot.

Here’s my take:

This allows method overriding, prototype inheritance, and preserves prototypal chain (instanceof).

From a subclass, you can access a superclass by referencing super or super.prototype.

The one big thing I don’t like is that, during the instantiation of the superclass to serve as the proto, the superclass is actually invoked (so that if a superclass actually “does” something, it’ll happen during the act of extension. This failure seems to be common to all approaches, though, and I don’t see any way around it without a iterative copy of members from one prototype to the other (which may, after all, turn out to be the best way to go).

Anyway, some POC:

And for those who don’t like to pollute the Function namespace, here’s the same thing procedurally:

(per Mat’s comment about clarifying default prototype member values, I’m including this link to his comments and my reply. Thanks Mat!)