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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:03:21+00:00 2026-06-03T22:03:21+00:00

This seems to be something that have been discussed by many. But unfortunately, I

  • 0

This seems to be something that have been discussed by many. But unfortunately, I couldn’t find an answer to my issue.
Here is a piece of code on Javascript inheritance (from a book):

function Car() {
    var self = this;
    self.type = "Car"
    self.go = function() {
        console.log("Going...");
    };
};

Toyota = function() { console.log("Original called"); };
Toyota.prototype = new Car();
Toyota.prototype.constructor = function() {
    var self = this;
    self.type = "Toyota";
    self.go = function() {
        console.log("A Toyota car is going...");
    }
};
Toyota.prototype.isJapaneseCar = true;

function TestCar() {
    console.log("Toyota.prototype.constructor: " + Toyota.prototype.constructor);
    var t = new Toyota();
    console.log("t.constructor: " + t.constructor);
    console.log(t.type);
};

And the output in Firefox console:

Toyota.prototype.constructor: function () {
    var self = this;
    self.type = "Toyota";
    self.go = function () {
        console.log("A Toyota car is going...");
    };
    }
Original called
t.constructor: function () {
    var self = this;
    self.type = "Toyota";
    self.go = function () {
        console.log("A Toyota car is going...");
    };
    }
Car

From the output, it is shown that the new Toyota() call:

var t = new Toyota();

didn’t invoke the Toyota.prototype.constructor function as expected, instead it still call the function defined in the first place:

Toyota = function() { console.log("Original called"); };

A post with high upvote count gave a fairly detailed explanation together with examples: it said “3. It executes the constructor function, using the new object whenever this is mentioned.” Does the “constructor” mentioned refer to prototype.constructor? How are the following 3 lines related:

  1. Toyota = function() { console.log(“Original called”); }
  2. Toyota.prototype.constructor = function() { …
  3. var t = new Toyota();

[EDIT] What confuses me most is why the constructor (Toyota.prototype.constructor) is not invoked when I call new Toyota()?

  • 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-03T22:03:22+00:00Added an answer on June 3, 2026 at 10:03 pm

    The constructor property in prototype object contains a reference to the function that constructs instances of that type of object. Hope I’m not trying to confuse here.

    For a string object you would see the constructor property referencing the String function (a.k.a constructor informally.)

    console.log("".constructor); // would print function String() { [native code] }
    

    which is why typically we would reassign the class (i.e., the function) constructor property to its own.

    Toyota.prototype.constructor = Toyota;
    
    var t = new Toyota();
    console.log(t.constructor); // prints function Toyota() { /* definition */ }
    

    Hope that answers your question.

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

Sidebar

Related Questions

Firstly, this seems like something that should have been asked before, but I cannot
This seems like a question that should have been answered already somewhere but I
This seems to be something obvious but I simply can't find info by googling.
This seems very basic and I must be missing something, but here goes anyways...
I am sure this topic has been discussed here before but I would like
Well I'm going crazy here. This is something that seems like it should be
I know this is something that has been discussed over and over, and I
This seems like something that could be quite useful and yet and I can't
This seems like I'm missing something obvious but I can't get redirects (>) to
This seems like it should be something very easy to do, but every time

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.