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 4616724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:01:26+00:00 2026-05-22T02:01:26+00:00

i don’t get why everyone is using Boy.prototype = new Human; to simulate inheritance.

  • 0

i don’t get why everyone is using Boy.prototype = new Human; to simulate inheritance. Look, what we want is the function’s of A right? we can do that without instantiating a new A (in fact instantiating a new A does give us undesirable results, in the sense that we are actually running the instantiating function which isn’t what we want)

So isn’t this a better solution?

for (var prop_name in Human.prototype) {
Object.defineProperty(
          Boy.prototype,
          prop_name,
          Object.getOwnPropertyDescriptor(Human.prototype,prop_name)
        );
}

Say we are that particular and want not only the enumerable properties in Human.prototype we could still achieve it by using Object.getOwnPropertyNames and calling it on the prototype chain, which in turn is available to us through Object.getPrototypeOf.

So what exactly is the benefit of doing Boy.prototype = new Human; to simulate inheritance when we have better options available to us?

  • 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-22T02:01:27+00:00Added an answer on May 22, 2026 at 2:01 am

    A better option is to create an intermediate to hold the prototype.

    function extend(clazz, superclass) {
        var intermediate = function() {};
        intermediate.prototype = superclass.prototype;
        clazz.prototype = new intermediate();
        // Following line is optional, but useful
        clazz.prototype.constructor = clazz;
    }
    

    This avoids unnecessary copying, but still means that you don’t need to instantiate an object that will do work in its constructor. It also sets up the prototype chain so that you can use instanceof. It also doesn’t result in superclass prototype contamination which some inheritance antipatterns can.

    For completeness, your subclass should call the superclass constructor in its constructor, which you can do with Superclass.call(this);.

    EDIT: Since ES5, you can replace calls to extend with

    Subclass.prototype = Object.create(Superclass.prototype);
    

    which does the same thing.

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

Sidebar

Related Questions

I don't want PHP errors to display /html, but I want them to display
I don't want to take the time to learn Obj-C. I've spent 7+ years
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
I don't know if this is the right place to ask about that, but
I don't know when to add to a dataset a tableadapter or a query
I don't edit CSS very often, and almost every time I need to go
I don't understand where the extra bits are coming from in this article about
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't remember whether I was dreaming or not but I seem to recall

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.