[thelist] Problems with prototypal inheritance in JavaScript

Jay Turley jayturley at gmail.com
Fri May 23 14:33:59 CDT 2008

Hi all-

I am currently trying to develop some namespaced code using a variant of
Heilmann's Revealing Module Pattern [1] and prototypal inheritance. The
problem I am running into is that when I inherit from a class, the
subclass's constructor does not have the ability to utilize the superclass's

I have uploaded a page showing the code in question and I have highlighted
the problem areas [2].

The main problem is that I had to end up using __proto__ to access the
prototype object's initialization function (which is called automatically by
the prototype object's constructor). This - to me - just feels wrong.  As
far as I understand, prototypal inheritance does not allow this type of
passing-on of information to the prototype's constructor.

However, before I added the __proto__ call, what would happen is that when a
new instance of ThingList was created, it would be created in an unstable
state. If it was the first call on a page, everything worked hunky-dory. But
if I were creating more than one ThingList on a page, the second would
invariably have problems with the _items and _keys arrays having contents in
them, instead of being initialized properly as new arrays. Using the
__proto__ allows me to properly initialized the Hash class from which
ThingList is inheriting.s

I would appreciated it if any JS gurus had any ideas about what I am doing
wrong, or could reassure me that this is the proper way to go.

Thanks a ton!


[2] http://www.esceeproperties.com/temp/example.html

More information about the thelist mailing list