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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:25:24+00:00 2026-06-14T00:25:24+00:00

There are 2 ways to call the parent constructor in the child. var A

  • 0

There are 2 ways to call the parent constructor in the child.

var A = function A() {
  this.x = 123;
};

var B = function B() {

  // 1. call directly
  A.call(this);

  // 2. call from prototype
  A.prototype.constructor.call(this);
};

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

Are there any situations when one would be safer/better than the other, or are they always equivalent?

  • 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-14T00:25:25+00:00Added an answer on June 14, 2026 at 12:25 am

    It’s always better to use the base constructor directly for the following reasons:

    1. It’s faster. The interpreter doesn’t need to access prototype.constructor.
    2. It’s safer. Consider the program below.

    A inherits from C, but I forgot to set A.prototype.constructor back to A. So it now points to C. This causes problems in the constructor B if we use the second method:

    var C = function C() {
        // some code
    };
    
    var A = function A() {
      this.x = 123;
    };
    
    A.prototype = Object.create(C.prototype);
    // I forgot to uncomment the next line:
    // A.prototype.constructor = A;
    
    var B = function B() {
    
      // 1. call directly
      A.call(this);
    
      // 2. call from prototype
      A.prototype.constructor.call(this); // A.prototype.constructor is C, not A
    };
    
    B.prototype = Object.create(A.prototype);
    B.prototype.constructor = B;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there ways to call a Windows command (ie: exe file) from a web
As is asked in this post , there are two ways to call another
Is there any ways to create my own audio file format? I'm planning to
Suppose we have 2 classes, Child, and the class from which it inherits, Parent.
hi are there any ways to call backing bean method in h:outputLink thanks Sunny
Is there any ways to short-up such chain call? if (obj && obj.prop &&
I am looking for all the ways one can call another activity from an
Need to call .delegateEvents() on all child views inside a parent collection view in
There is this Telerik's RadTreeView (Silverlight Version) control I'd like to extend (inherit from).
What ways there are for doing a one way XML serialization in .Net? XmlSerializer

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.