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

  • Home
  • SEARCH
  • 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 8759413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:47:50+00:00 2026-06-13T14:47:50+00:00

i am trying to figure out how the code below works. Can somebody explain

  • 0

i am trying to figure out how the code below works. Can somebody explain what does it mean when it says ” create an uber property that points to the parent’s prototype object.” What exactly does it mean when it says “this.constructor.uber” points to parent’s prototype? i’ve been scratching my head for a while now. i would be really thankful if somebody could explain what’s happening in function Shape().

function Shape() {}
// augment prototype
Shape.prototype.name = 'shape';
Shape.prototype.toString = function () {
    var result = [];
    if (this.constructor.uber) {
        result[result.length] = this.constructor.uber.toString();
    }
    result[result.length] = this.name;
    return result.join(', ');
};


function TwoDShape() {}
// take care of inheritance
var F = function () {};
F.prototype = Shape.prototype;
TwoDShape.prototype = new F();
TwoDShape.prototype.constructor = TwoDShape;
TwoDShape.uber = Shape.prototype;
// augment prototype
TwoDShape.prototype.name = '2D shape';

function Triangle(side, height) {
    this.side = side;
    this.height = height;
}
// take care of inheritance
var F = function () {};
F.prototype = TwoDShape.prototype;
Triangle.prototype = new F();
Triangle.prototype.constructor = Triangle;
Triangle.uber = TwoDShape.prototype;
// augment prototype
Triangle.prototype.name = 'Triangle';
Triangle.prototype.getArea = function () {
    return this.side * this.height / 2;
}

var my = new Triangle(5, 10);
my.toString()

Output: "shape,2Dshape,Triangle"

  • 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-06-13T14:47:54+00:00Added an answer on June 13, 2026 at 2:47 pm

    In Javascript inheritance, there is no support for accessing a super method, so what I can see here with uber, is having access to its parent methods.
    Name it parent as following:
    TwoDShape.parent = Shape.prototype

    That way you can have direct access to a parent property: TwoDShape.parent.name should return 'shape'.

    What toString() is actually doing here, is:

    var result = []; //declare an array
    if (this.constructor.parent) { //if there is a parent prototype
        result[0] = this.constructor.parent.toString(); //set the 0 position of result with the return value of parent's toString() method.
    }
    result[result.length] = this.name; //set the position (0 or 1, if we had a parent it will be 1, otherwise 0) with the current name.
    return result.join(', '); //return the names joined with a comma
    

    Note that I changed the uber to parent so its more readable. the first assignment of result will always be 0, so it was not necessary the call to result.length.

    What the calls would return for each object?:
    Shape.toString();: 'shape' (there’s no parent)
    TwoDShape.toString();: 'shape, 2D shape' ('shape' for the call to Shape.toString();, and '2D shape' for its own name, joined).
    Triangle.toString();: 'shape, 2D shape, Triangle' ('shape, 2D shape' for the call to TwoDShape.toString();, and 'Triangle' for its own name, joined).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out what's wrong with my mysqli code below. The data
Note my code below. I am trying to figure out why my data is
I am trying to figure out what the below syntax do. It's code from
Trying to figure out this pseudo code. The following is assumed.... I can only
Can anyone explain how compilation works? I can't seem to figure out how compilation
i'm trying to figure out the code for the jquery selector test found at
I'm trying to figure out why this code won't compile. I have interface A
I'm trying to figure out whether the code located after throw new Exception in
I'm trying to figure out how to use Emacs Code Browser (ECB) and one
I am trying to figure out how to simplify this piece of code. The

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.