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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:37:36+00:00 2026-05-30T23:37:36+00:00

When making the prototypal inheritance, it’s asked to refer the child’s constructor back to

  • 0

When making the prototypal inheritance, it’s asked to refer the child’s constructor back to itself below,

A = function() {} 
B = function() {} 
B.prototype = new A;
B.prototype.constructor = B;

What would take adverse effect if not?

EDIT

  • As @GGG & @CMS have explained, the constructor alignment takes no
    effect on creating the child object by new Child(...), but is
    necessary to correctly reflect the child object’s constructor later.
  • @GGG has also suggested a defensive alternative to extend
    the prototype chain. While Child.prototype = new Parent(...)
    includes parent’s properties to child, Child.prototype =
    Object.create(Parent.prototype)
    doesn’t.
  • 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-30T23:37:37+00:00Added an answer on May 30, 2026 at 11:37 pm

    First, please don’t do this:

    B.prototype = new A;
    

    Do this instead (shim Object.create for old browsers):

    B.prototype = Object.create(A.prototype);
    

    As for constructor, nothing will break if you don’t do this, but if you don’t:

    A = function() {};
    var a = new A();
    console.log(a.constructor); // A
    
    B = function() {};
    var b = new B();
    console.log(b.constructor); // A (!)
    

    …setting the constructor property of the prototype back to the actual constructor function allows you to do this:

    B.prototype.constructor = B;
    var b = new B();
    console.log(b.constructor); // B
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making this prototype script to work: function removing () { *var ids =
I've been tasked with making a prototype web application, and i'm debating between using
We recently built a web app using Prototype, making a fair amount of use
Hey, I'm making a simple user friendly css editor using Prototype. Anyway, I was
After making some changes in my models (eg. new field in a model and
I am making a prototype client & server so that I can understand how
I am messing around with C# and am making a prototype GUI (with no
So I'm using jqGrid with my mvc.net / Ling2Sql prototype site that I'm making
How can I go about making a child class override a privileged method of
I am making a prototype of a Silverlight application in Expression Blend 4 and

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.