Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > prototype __proto__ super and delegation

Thread Tools

prototype __proto__ super and delegation

Posts: n/a
Hello JS Gurus,

One thing I haven't figured out about javascript is the treatment of

Inheritence, whether prototypes or class-based, is just a shorthand
form of delegation (leaving aside dynamic dispatch).

In Java a derived class serves as a wrapper for its superclass. The
derived class can easily access members of its super class using the
nice "super" keyword. Why, in javascript, is this functionality buried
in the unofficial "__proto__" property? It seems that it must have
been the intent of the language designer that explicitly accessing the
prototype chain is a bad thing for some reason, although I can't see
any reason.

By googling, you can find a lot of weird hacks to add "super"-like
functionality to javascript, although many of them look misguided to
me. It certainly seems that this is a commonly confusing part of the

If __proto__ were an official part of the language, implementing a
decorator or proxy pattern would be nicely simplified compared to
class-based inheritence. The "before-and-after" style of AOP (which is
just another style of shorthand for delegation) would be possible
without any crazy tricks.

So, anyone care to set me straight? Why isn't __proto__ or something
like it a well defined part of javascript? Shouldn't it be??



Reply With Quote
Posts: n/a
Hmmm, apparently GMail hiccuped. I wrote a reply to Thomas
'PointedEars', but I guess it got disappeared.

To misquote myself:

Thanks for the replies! The AOP (Aspect Oriented Programming)
reference was just an attempt to explain the kind of use-case I had in
mind. The goal of AOP is to modularize certain kinds of operations
that tend to get intermingled with other code. One way AOP goes about
doing that is the "before-and-after" pattern.

Typical examples include transactions, security checks, and (what I
was trying to do) lazy loading. AOP wasn't really the important part.
The main goal I had was to define some functionality in one object.
Then use a second wrapper object to layer on additional functionality.

In my case the primary function was translating codes in a URL from
one format to another. The secondary functionality was to lazily
populate a big lookup table.

It seems to me that prototype based inheritence could easily support
some really clean patterns for using delegation as a means to
decompose a problem into modular peices. That's really what I was

I have a suspicion that the shift in thinking required to use dynamic
languages well is of at least the same magnitude as that required to
go from procedural to OO languages. Thanks for helping me get there!


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using __proto__ seems to be slower than applying prototype propertiesmanually webEater Javascript 3 06-15-2010 05:16 PM
delegation question, where I want prototype style delegation Sam Roberts Ruby 4 05-07-2008 05:48 AM
prototype __proto__ super and delegation cbare Javascript 8 10-31-2007 05:01 PM
super.super.super how? Java 24 02-24-2005 10:51 PM
Potential improvement on delegation via explicit calls and super Robert Dick Python 1 12-17-2004 02:48 PM