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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:07:31+00:00 2026-05-17T18:07:31+00:00

I find the behaviour of this piece of code puzzling, why is the constructor

  • 0

I find the behaviour of this piece of code puzzling, why is the constructor of child not Child? Can someone please explain this to me?

function Parent() {
    this.prop1 = "value1";
    this.prop2 = "value2";
}

function Child() {
    this.prop1 = "value1b";
    this.prop3 = "value3";
}
Child.prototype = new Parent();

var child = new Child();

// this is expected
console.log(child instanceof Child); //true
console.log(child instanceof Parent); //true

// what??
console.log(child.constructor == Child); //false
console.log(child.constructor == Parent); //true
  • 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-17T18:07:31+00:00Added an answer on May 17, 2026 at 6:07 pm

    As Pointy has pointed out, in his answer

    The “constructor” property is a
    reference to the function that created
    the object’s prototype, not the object
    itself.

    The usual way to deal with this is to augment the object’s prototype constructor property after assigning to the prototype

    function Parent() {
        this.prop1 = "value1";
        this.prop2 = "value2";
    }
    
    function Child() {
        this.prop1 = "value1b";
        this.prop3 = "value3";
    }
    Child.prototype = new Parent();
    
    // set the constructor to point to Child function
    Child.prototype.constructor = Child;
    
    var child = new Child();
    
    // this is expected
    console.log(child instanceof Child); //true
    console.log(child instanceof Parent); //true
    
    // corrected
    console.log(child.constructor == Child); // now true
    console.log(child.constructor == Parent); // now false
    
    console.log(Child.prototype.constructor); // Child
    console.log(Parent.prototype.constructor); // Parent
    

    I can’t recommend Stoyan Stefanov’s Object Oriented JavaScript enough which covers Prototype and Inheritance in some detail (get the second edition if you can as it addresses some critiques of the first edition).

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

Sidebar

Related Questions

I can´t find an explanation to this behaviour (SQL Server 2008 + PHP 5.2.14)
Hi was I hoping someone would help understand this behaviour of the below code.
I have searched but could not find the reason for this behavior. I have
Auto-binding of request params seems like default behaviour, but I can't find a lot
i know that .NET String class uses such behaviour, but I can't find any
This is a very basic MySQL question but I could not find an answer.
I've seen this behaviour in many websites and web applications but I'm not able
For example, in this piece of code, if line [a] is commented out, the
I have a problem with this jQuery code: $(document).ready( function(){ alert($('#search').val()); var dummyInput =
Forgive me if this has been asked elsewhere. I was not able to find

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.