prototype __proto__ super and delegation
Hello JS Gurus,
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
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
By googling, you can find a lot of weird hacks to add "super"-like
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
Re: prototype __proto__ super and delegation
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!
|All times are GMT. The time now is 07:51 AM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.