prototype __proto__ super and delegation

Discussion in 'Javascript' started by cbare, Oct 30, 2007.

  1. cbare

    cbare Guest

    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??


    cbare, Oct 30, 2007
    1. Advertisements

  2. cbare

    cbare Guest

    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!

    cbare, Nov 1, 2007
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    super.super.super how?

    Guest, Feb 19, 2005, in forum: Java
    Darryl Pierce
    Feb 24, 2005
  2. Robert Dick
    Thomas Guettler
    Dec 17, 2004
  3. Sam Roberts
    Sam Roberts
    May 7, 2008
  4. cbare
    John G Harris
    Oct 31, 2007
  5. webEater
    Thomas 'PointedEars' Lahn
    Jun 15, 2010

Share This Page