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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:58:44+00:00 2026-05-27T09:58:44+00:00

In the section about inheritance in the MDN article Introduction to Object Oriented Javascript

  • 0

In the section about inheritance in the MDN article Introduction to Object Oriented Javascript, I noticed they set the prototype.constructor:

// correct the constructor pointer because it points to Person
Student.prototype.constructor = Student;  

Does this serve any important purpose? Is it okay to omit it?

  • 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-27T09:58:45+00:00Added an answer on May 27, 2026 at 9:58 am

    It’s not always necessary, but it does have its uses. Suppose we wanted to make a copy method on the base Person class. Like this:

    // define the Person Class  
    function Person(name) {
        this.name = name;
    }  
    
    Person.prototype.copy = function() {  
        // return new Person(this.name); // just as bad
        return new this.constructor(this.name);
    };  
    
    // define the Student class  
    function Student(name) {  
        Person.call(this, name);
    }  
    
    // inherit Person  
    Student.prototype = Object.create(Person.prototype);
    

    Now what happens when we create a new Student and copy it?

    var student1 = new Student("trinth");  
    console.log(student1.copy() instanceof Student); // => false
    

    The copy is not an instance of Student. This is because (without explicit checks), we’d have no way to return a Student copy from the “base” class. We can only return a Person. However, if we had reset the constructor:

    // correct the constructor pointer because it points to Person  
    Student.prototype.constructor = Student;
    

    …then everything works as expected:

    var student1 = new Student("trinth");  
    console.log(student1.copy() instanceof Student); // => true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On MSDN I noticed a section about a Portable Class Library , under Version
I've read this book section about git branches. I have create a branch called
I am about to add a section to an ASP.NET app (VB.NET codebehind) that
How do I go about making an image or section of the page full
I am thinking about creating a new repository in SVN for a section of
See section /* Common Classes */ of this page. http://webdesign.about.com/od/css/a/master_stylesht_2.htm are these css classes
For the about section of my app, I want to display some multiline text.
I want to add the field bio to about section of the document.
In the book Java in a Nutshell, chapter 3, section 3.5 Subclasses and Inheritance,
I found in demos section about the Data picker. But do we have a

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.