Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6786867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:17:47+00:00 2026-05-26T17:17:47+00:00

Basically is there a good elegant mechanism to emulate super with syntax that is

  • 0

Basically is there a good elegant mechanism to emulate super with syntax that is as simple as one of the following

  • this.$super.prop()
  • this.$super.prop.apply(this, arguments);

Criteria to uphold are :

  1. this.$super must be a reference to the prototype. i.e. if I change the super prototype at run-time this change will be reflected. This basically means it the parent has a new property then this should be shown at run-time on all children through super just like a hard coded reference to the parent would reflect changes
  2. this.$super.f.apply(this, arguments); must work for recursive calls. For any chained set of inheritance where multiple super calls are made as you go up the inheritance chain, you must not hit the recursive problem.
  3. You must not hardcode references to super objects in your children. I.e. Base.prototype.f.apply(this, arguments); defeats the point.
  4. You must not use a X to JavaScript compiler or JavaScript preprocessor.
  5. Must be ES5 compliant

The naive implementation would be something like this.

var injectSuper = function (parent, child) {
  child.prototype.$super = parent.prototype;
};

But this breaks condition 2.

The most elegant mechanism I’ve seen to date is IvoWetzel’s eval hack, which is pretty much a JavaScript preprocessor and thus fails criteria 4.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:17:47+00:00Added an answer on May 26, 2026 at 5:17 pm

    I don’t think there is a “free” way out of the “recursive super” problem you mention.

    We can’t mess with the this because doing so would either force us to change prototypes in a nonstandard way, or move us up the proto chain, losing instance variables. Therefore the “current class” and “super class” must be known when we do the super-ing, without passing that responsibility to this or one of its properties.

    There are many some things we could try doing but all I can think have some undesireable consequences:

    • Add super info to the functions at creation time, access it using arguments.calee or similar evilness.
    • Add extra info when calling the super method

      $super(CurrentClass).method.call(this, 1,2,3)
      

      This forces us to duplicate the current class name (so we can look up its superclass in some super dictionary) but at least it isn’t as bad as having to duplicate the superclass name, (since coupling against the inheritance relationships if worse then the inner coupling with a class’ own name)

      //Normal Javascript needs the superclass name
      SuperClass.prototype.method.call(this, 1,2,3);
      

      While this is far from ideal, there is at least some historical precedent from 2.x Python. (They “fixed” super for 3.0 so it doesn’t require arguments anymore, but I am not sure how much magic that involved and how portable it would be to JS)


    Edit: Working fiddle

    var superPairs = [];
    // An association list of baseClass -> parentClass
    
    var injectSuper = function (parent, child) {
        superPairs.push({
            parent: parent,
            child: child
        });
    };
    
    function $super(baseClass, obj){
        for(var i=0; i < superPairs.length; i++){
            var p = superPairs[i];
            if(p.child === baseClass){
                return p.parent;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to design this very simple website. Basically there are multiple pages
I have some localization problems in my webpage. There are basically two problems (that
I like to generate a thread dump programmatically. I've learned that there a basically
Are there any more generic tools that can compile or basically merge multiple PHP
Is there any name for the following DB table design: Basically we have generic
I basically need to check if there is an easier way to do this
Is there any simple way to programatically colorize images in .NET? Basically we have
Is there a way to emulate mixins or traits in java? basically, I need
Is there a good tutorial on the net somewhere that delineates the steps needed
Are there any good tools to generate a simple C# class from xml. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.